U2U.AspNetCore.CleanArchitecture 2.0.0-alpha

This is a prerelease version of U2U.AspNetCore.CleanArchitecture.
There is a newer version of this package available.
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
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="2.0.0-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add U2U.AspNetCore.CleanArchitecture --version 2.0.0-alpha
#r "nuget: U2U.AspNetCore.CleanArchitecture, 2.0.0-alpha"
#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=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 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. 
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,015 8/18/2020
3.1.0 1,138 1/2/2020
2.1.1 1,327 9/22/2018
2.1.0 1,259 9/18/2018
2.0.0 1,670 1/14/2018
2.0.0-alpha 1,521 12/24/2017