Skip to content

Dot net pattern

addExternalDependencies

addExternalDependencies(projectName: str, path: str)

Add external dependencies to .NET Core projects.

This function adds external dependencies to various .NET Core projects within the solution.

---Application AutoMapper FluentValidation.AspNetCore Microsoft.Extensions.DependencyInjection Swashbuckle.AspNetCore.Annotations

---Domain Microsoft.Extensions.DependencyInjection BE_Izio.Core.Biblioteca

---Infra.DependencyInjection Swashbuckle.AspNetCore.SwaggerUI

Args: - projectName (str): The name of the main project. - path (str): The file system path where the DataAccess project is located.

Source code in izio_cli/pattern/dot_net_pattern.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
def addExternalDependencies(projectName: str, path: str):
    """
    Add external dependencies to .NET Core projects.

    This function adds external dependencies to various .NET Core projects within the solution.

    ---Application
        AutoMapper
        FluentValidation.AspNetCore
        Microsoft.Extensions.DependencyInjection
        Swashbuckle.AspNetCore.Annotations

    ---Domain
        Microsoft.Extensions.DependencyInjection
        BE_Izio.Core.Biblioteca

    ---Infra.DependencyInjection
        Swashbuckle.AspNetCore.SwaggerUI

    Args:
    - projectName (str): The name of the main project.
    - path (str): The file system path where the DataAccess project is located.
    """
    # TODO: Add the new Izio Library package to the Domain and  project
    run_command(
        [
            "dotnet",
            "add",
            f"{projectName}.Domain{os.sep}{projectName}.Domain.csproj",
            "package",
            "Library",
            "--source",
            "https://api.nuget.org/v3/index.json"
        ],
        path=path,
    )

    run_command(
        [
            "dotnet",
            "add",
            f"{projectName}.Domain{os.sep}{projectName}.Domain.csproj",
            "package",
            "Microsoft.Extensions.DependencyInjection",
        ],
        path=path,
    )

    run_command(
        [
            "dotnet",
            "add",
            f"{projectName}.Infra.DependencyInjection{os.sep}{projectName}.Infra.DependencyInjection.csproj",
            "package",
            "Swashbuckle.AspNetCore.SwaggerUI",
        ],
        path=path,
    )

    run_command(
        [
            "dotnet",
            "add",
            f"{projectName}.Application{os.sep}{projectName}.Application.csproj",
            "package",
            "AutoMapper",
        ],
        path=path,
    )

    run_command(
        [
            "dotnet",
            "add",
            f"{projectName}.Application{os.sep}{projectName}.Application.csproj",
            "package",
            "FluentValidation.AspNetCore",
        ],
        path=path,
    )

    run_command(
        [
            "dotnet",
            "add",
            f"{projectName}.Application{os.sep}{projectName}.Application.csproj",
            "package",
            "Microsoft.Extensions.DependencyInjection",
        ],
        path=path,
    )

    run_command(
        [
            "dotnet",
            "add",
            f"{projectName}.Application{os.sep}{projectName}.Application.csproj",
            "package",
            "Swashbuckle.AspNetCore.Annotations",
        ],
        path=path,
    )

addReferences

addReferences(projectName, path)

Add project references in a .NET Core solution.

This function sets up references between different projects in a .NET Core solution based on a predefined structure.

- Api: ["Infra.DependencyInjection"],
- Application: ["Domain", "Infra.DependencyInjection"],
- Infra.DataAccess: ["Offer.Domain"],
- Infra.DependencyInjection: ["Offer.Domain"],
- Domain: none,

Args: - projectName (str): The name of the main project. - path (str): The file system path where the projects are located.

Source code in izio_cli/pattern/dot_net_pattern.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
def addReferences(projectName, path):
    """
    Add project references in a .NET Core solution.

    This function sets up references between different projects in a .NET Core solution based on a predefined structure.

        - Api: ["Infra.DependencyInjection"],
        - Application: ["Domain", "Infra.DependencyInjection"],
        - Infra.DataAccess: ["Offer.Domain"],
        - Infra.DependencyInjection: ["Offer.Domain"],
        - Domain: none,

    Args:
    - projectName (str): The name of the main project.
    - path (str): The file system path where the projects are located.
    """

    referencies = {
        "Api": ["Infra.DependencyInjection"],
        "Application": ["Domain"],
        "Infra.DataAccess": ["Domain"],
        "Infra.DependencyInjection": ["Application", "Domain", "Infra.DataAccess"],
    }
    for project, refs in referencies.items():
        for ref in refs:
            run_command(
                [
                    "dotnet",
                    "add",
                    f"{projectName}.{project}{os.sep}{projectName}.{project}.csproj",
                    "reference",
                    f"{projectName}.{ref}{os.sep}{projectName}.{ref}.csproj",
                ],
                path=path,
            )

createNetCoreProjects

createNetCoreProjects(path, projectName, projects)

Create .NET Core projects within a solution.

This function iterates over a list of projects and creates each one using the 'dotnet new' command. It also adds each project to the solution file.

Args: - path (str): The file system path where the projects should be created. - projectName (str): The name of the project. - projects (list): A list of project names to be created.

Source code in izio_cli/pattern/dot_net_pattern.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
def createNetCoreProjects(path, projectName, projects):
    """
    Create .NET Core projects within a solution.

    This function iterates over a list of projects and creates each one using the 'dotnet new' command. It also adds each project to the solution file.

    Args:
    - path (str): The file system path where the projects should be created.
    - projectName (str): The name of the project.
    - projects (list): A list of project names to be created.
    """

    for project in projects:
        print(f"Creating project: {project}")
        run_command(
            [
                "dotnet",
                "new",
                "webapi" if project == f"{projectName}.Api" else "classlib",
                "-n",
                f"{project}",
            ],
            path=path,
        )
        run_command(
            [
                "dotnet",
                "sln",
                "add",
                f"{project}" + os.sep + f"{project}.csproj",
            ],
            path=path,
        )

createSubmodules

createSubmodules(path, projectName)

Create submodules for various projects in a .NET Core solution.

This function creates a set of predefined submodules (directories) for different projects within the solution, such as Extensions, Services, DTOs, Validators, etc.

...Api/Controllers
...Application/Dtos
...Application/Dtos/Responses
...Application/Interfaces
...Application/Mappers
...Application/Services
...Application/Validators
...Domain/Entities
...Domain/Interfaces
...Domain/Validations
...Infra.DataAccess/Repository
...Infra.DependencyInjection/Infra

Args: - path (str): The file system path where the submodules should be created. - projectName (str): The name of the main project.

Source code in izio_cli/pattern/dot_net_pattern.py
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
def createSubmodules(path, projectName):
    """
    Create submodules for various projects in a .NET Core solution.

    This function creates a set of predefined submodules (directories) for different projects within the solution, such as Extensions, Services, DTOs, Validators, etc.

        ...Api/Controllers
        ...Application/Dtos
        ...Application/Dtos/Responses
        ...Application/Interfaces
        ...Application/Mappers
        ...Application/Services
        ...Application/Validators
        ...Domain/Entities
        ...Domain/Interfaces
        ...Domain/Validations
        ...Infra.DataAccess/Repository
        ...Infra.DependencyInjection/Infra


    Args:
    - path (str): The file system path where the submodules should be created.
    - projectName (str): The name of the main project.
    """
    subMobules = [
        projectName + f".Api{os.sep}Controllers",
        projectName + f".Application{os.sep}Dtos",
        projectName + f".Application{os.sep}Dtos{os.sep}Responses",
        projectName + f".Application{os.sep}Interfaces",
        projectName + f".Application{os.sep}Mappers",
        projectName + f".Application{os.sep}Services",
        projectName + f".Application{os.sep}Validators",
        projectName + f".Domain{os.sep}Entities",
        projectName + f".Domain{os.sep}Interfaces",
        projectName + f".Domain{os.sep}Validations",
        projectName + f".Infra.DataAccess{os.sep}Repository",
        projectName + f".Infra.DataAccess{os.sep}Configuration",
        projectName + f".Infra.DependencyInjection{os.sep}Infra",
    ]
    for sub in subMobules:
        create_directory(f"{path}{os.sep}{sub}")