U2U.AspNetCore.CleanArchitecture
3.1.0
See the version list below for details.
dotnet add package U2U.AspNetCore.CleanArchitecture --version 3.1.0
NuGet\Install-Package U2U.AspNetCore.CleanArchitecture -Version 3.1.0
<PackageReference Include="U2U.AspNetCore.CleanArchitecture" Version="3.1.0" />
paket add U2U.AspNetCore.CleanArchitecture --version 3.1.0
#r "nuget: U2U.AspNetCore.CleanArchitecture, 3.1.0"
// Install U2U.AspNetCore.CleanArchitecture as a Cake Addin #addin nuget:?package=U2U.AspNetCore.CleanArchitecture&version=3.1.0 // Install U2U.AspNetCore.CleanArchitecture as a Cake Tool #tool nuget:?package=U2U.AspNetCore.CleanArchitecture&version=3.1.0
U2U.AspNetCore.CleanArchitecture
This package makes it easier to keep dependencies between Infrastructure and Web Site projects separately, 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 at 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 | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.Configuration (>= 3.1.0)
- Microsoft.Extensions.Configuration.Binder (>= 3.1.0)
- Microsoft.Extensions.DependencyInjection (>= 3.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.