U2U.AspNetCore.CleanArchitecture 3.1.0

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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                
#r "nuget: U2U.AspNetCore.CleanArchitecture, 3.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.2.0 2,407 8/18/2020
3.1.0 1,165 1/2/2020
2.1.1 1,369 9/22/2018
2.1.0 1,297 9/18/2018
2.0.0 1,701 1/14/2018
2.0.0-alpha 1,548 12/24/2017