AttributeBasedRegistration.Autofac 2.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AttributeBasedRegistration.Autofac --version 2.2.1                
NuGet\Install-Package AttributeBasedRegistration.Autofac -Version 2.2.1                
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="AttributeBasedRegistration.Autofac" Version="2.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AttributeBasedRegistration.Autofac --version 2.2.1                
#r "nuget: AttributeBasedRegistration.Autofac, 2.2.1"                
#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 AttributeBasedRegistration.Autofac as a Cake Addin
#addin nuget:?package=AttributeBasedRegistration.Autofac&version=2.2.1

// Install AttributeBasedRegistration.Autofac as a Cake Tool
#tool nuget:?package=AttributeBasedRegistration.Autofac&version=2.2.1                

AttributeBasedRegistration

Build Status

Library allowing registering services with Autofac and Microsoft's DI container via attributes. Additionally contains various extensions to Autofac and Microsoft's DI container.

Features

Set of attributes allowing automatic registration:

  • [ServiceImplementation] - marks the class as an implementation of a service, allows for a quick definition providing a few possible ctors
  • [RegisterAs] - explicitly defines service types or a registration strategy
  • [Lifetime] - explicitly defines the lifetime with which the service should be registered (Autofac's based - Microsoft's DI equivalent will be used) - some supported only with Autofac
  • [EnableInterception] - enables interception on the service, in theory supports intercepting classes and interfaces (or both) (Intercept enum) though intercepting classes sometimes suffers from weird Castle.Core bugs thus when using interception it is encouraged to use interface service types - supported only with Autofac
  • [InterceptedBy] - defines interceptor types that should intercept calls to the service - supported only with Autofac
  • [FindConstructorsWith] - defines a constructor finder to use during creation of the service instance, supports only parameterless ctors and can't be used in conjunction with interceptors - supported only with Autofac
  • [DecoratedBy] - defines types that decorate this service - supported only with Autofac

The usage of the Lifetime attribute versus supplying the lifetime to the ServiceImplementation is per users taste, the data from the more specific attribute will take precedence.

Similar to the above, using multiple RegisterAs or InterceptedBy attributes versus one and supplying multiple types is per users taste - types will be aggregated from all attributes.

Installation

To pick up and register services via attributes use the extensions method on ContainerBuilder or IServiceCollection provided by the library:

builder.AddAttributeDefinedServices(assembliesToScan);

Documentation

Documentation available at https://mikym.github.io/AttributeBasedRegistration/.

Example usage


public interface ICustomService1
{
}

[ServiceImplementation]
[RegisterAs(typeof(ICustomService))]
[Lifetime(ServiceLifetime.InstancePerLifetimeScope)]
[DecoratedBy(1, typeof(ISomeDecorator))]
[EnableInterception(InterceptionStrategy.Interface)]
[InterceptedBy(1, typeof(ISomeInterceptor))]
public class CustomService1 : ICustomService1
{
}

public interface ICustomService2
{
}

[ServiceImplementation(ServiceLifetime.SingleInstance, RegistrationStrategy.AsConventionNamedInterface)]
public class CustomService2 : ICustomService2
{
}

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on AttributeBasedRegistration.Autofac:

Package Downloads
DataExplorer

Library featuring an opinionated, reusable data access layer offering abstractions and implementations for SQL storages (EF Core).

ResultCommander.Autofac

Library featuring a command handler pattern.

ResultCQRS.Autofac

Library featuring CQRS pattern.

DataExplorer.Unstable

Library featuring common patterns in regard to working with data storages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.7 227 7/23/2024
2.2.6 470 1/24/2024
2.2.5 188 1/22/2024
2.2.4 108 1/22/2024
2.2.3 556 11/22/2023
2.2.2 493 11/20/2023
2.2.1 122 11/20/2023
2.2.0 183 11/20/2023
2.1.5 1,425 8/18/2023
2.1.4 859 7/10/2023
2.1.3 484 6/25/2023
2.1.2 591 5/10/2023
2.1.1 891 4/3/2023
2.1.0 1,187 3/14/2023
2.0.10 4,126 1/9/2023
2.0.9 1,107 12/22/2022
2.0.8 283 12/22/2022