U2U.AspNetCore.CleanArchitecture 3.1.0

Use Clean Architecture without direct dependencies in code to Infra and Code.

Install-Package U2U.AspNetCore.CleanArchitecture -Version 3.1.0
dotnet add package U2U.AspNetCore.CleanArchitecture --version 3.1.0
<PackageReference Include="U2U.AspNetCore.CleanArchitecture" Version="3.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add U2U.AspNetCore.CleanArchitecture --version 3.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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&lt;T&gt; 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)));

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&lt;T&gt; 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)));

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.1.0 67 1/2/2020
2.1.1 205 9/22/2018
2.1.0 186 9/18/2018
2.0.0 452 1/14/2018
2.0.0-alpha 401 12/24/2017