U2U.AspNetCore.CleanArchitecture
2.0.0-alpha
See the version list below for details.
dotnet add package U2U.AspNetCore.CleanArchitecture --version 2.0.0-alpha
NuGet\Install-Package U2U.AspNetCore.CleanArchitecture -Version 2.0.0-alpha
<PackageReference Include="U2U.AspNetCore.CleanArchitecture" Version="2.0.0-alpha" />
paket add U2U.AspNetCore.CleanArchitecture --version 2.0.0-alpha
#r "nuget: U2U.AspNetCore.CleanArchitecture, 2.0.0-alpha"
// Install U2U.AspNetCore.CleanArchitecture as a Cake Addin #addin nuget:?package=U2U.AspNetCore.CleanArchitecture&version=2.0.0-alpha&prerelease // Install U2U.AspNetCore.CleanArchitecture as a Cake Tool #tool nuget:?package=U2U.AspNetCore.CleanArchitecture&version=2.0.0-alpha&prerelease
U2U.AspNetCore.CleanArchitecture
This package makes it easier keep dependencies between Infrastructure and Web Site projects seperate, as described in Clean Architecture.
Usage
In your Infrastructure project you create a DependencyInjection
class with extension
methods that add needed dependencies, attributed with [AutoConfig]
[AutoConfig]
public static class DependencyInjection
{
[AutoConfig]
public static IServiceCollection AddCurrencyConverter(this IServiceCollection services)
=> services.AddTransient<ICurrencyConverterService, CurrencyConverterService>();
[AutoConfig("GamesDb")]
public static IServiceCollection AddGamesDb(this IServiceCollection services, string connectionString, [MigrationAssembly] string migrationAssembly)
=> services.AddDbContext<GamesDb>(optionsBuilder =>
optionsBuilder.UseSqlServer(connectionString,
sqlServerOptions => sqlServerOptions.MigrationsAssembly(migrationAssembly)));
In your Web Site project you call the AddAutoConfig
method, passing in the
Configuration
instance.
services.AddAutoConfig(Configuration);
This method will look the the Infrastructure project for AutoConfig
methods and call them.
Configuration
So how does AddAutoConfig
know where to look for AutoConfig
methods?
Your project should have an AutoConfig
section, containing a list of assemblies to search,
and the MigrationAssembly
name for EF Migrations. For example:
"AutoConfig": {
"Assemblies": [
"Infra"
],
"MigrationAssembly":"WebApp"
}
EF Migrations
When working with EF Core migrations you need to specify two things. First of all the name
of the MigrationsAssembly
, which can be found in configuration. But you also need to specify
the connection string for each DbContext
.
If your Infrastructure project calls AddDbContext<T>
how does it access configuration?
The AutoConfig
attribute has an overload, allowing you to specify the
name of the connection string. The AddAutoConfig
method will then lookup the value of the
connection string and pass it to the method as the connectionString
argument.
[AutoConfig("GamesDb")]
public static IServiceCollection AddGamesDb(this IServiceCollection services, string connectionString, [MigrationAssembly] string migrationAssembly)
=> services.AddDbContext<GamesDb>(optionsBuilder =>
optionsBuilder.UseSqlServer(connectionString,
sqlServerOptions => sqlServerOptions.MigrationsAssembly(migrationAssembly)));
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.0
- Microsoft.Extensions.DependencyInjection (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.