Skip to content

Manually registering types in an IoC container can be a tedious task. This extension to Autofac aims to help automatically registering types with common, built-in and extensible conventions.

Notifications You must be signed in to change notification settings

VaudoiseAssurances/Autofac.BindingByConvention

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autofac.BindingByConvention

master develop NuGet
Master Build status Develop Build status NuGet version

Manually registering types in an IoC container can be a tedious task. This extension to Autofac aims to help automatically registering types with common, built-in and extensible conventions.

How to use it

Installation

Install with NuGet. See NuGet package page for more information.

Usage and examples

The following example will create a new ContainerBuilder and

  • Register assembly types located in a list of assemblies by convention...
  • ... to the contracts (interfaces) that have...
  • ... a name matching a convention where the interface's type name has a leading I ...
  • ... except if this interface type is listed as a specified list of interfaces to ignore ...
  • ... and except if the contracts (interfaces) are marked with the NoBindingByConventionAttribute attribute...
  • ... Instances will be instanciated per-dependency (each resolved type is a different instance.)
var builder = new ContainerBuilder();

builder
    .RegisterAssemblyTypes(listOfAssemblies)
    .ByConvention().ToTheContractsWith()
        .NameMatching(InterfaceTypeName.HasLeadingI)
        .Except
            .Types(listOfInterfacesToIgnore)
        .Except
            .ContractsMarkedWith<NoBindingByConventionAttribute>()
        .Instanciated<PerDependency>();

Contribute

Build/Run

Build the project with dotnet standard 2

About

Manually registering types in an IoC container can be a tedious task. This extension to Autofac aims to help automatically registering types with common, built-in and extensible conventions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages