Skip to content

Assembly registration

Peter Csajtai edited this page Jul 10, 2020 · 4 revisions

You can register services defined within a given assembly:

container.RegisterAssembly(assembly);

In this case, all services defined in the given assembly will be registered by their implemented interfaces, base types, and themselves.

You can also register an assembly by using just a type defined in it:

container.RegisterAssemblyContaining<Drizzt>();

You can pass an assembly collection also:

container.RegisterAssemblies(new[] { assembly1, assembly2 });

Filter

You can specify which services you want to register from an assembly with a filter predicate:

container.RegisterAssembly(assembly, type => type == typeof(Drizzt));
//or
container.RegisterAssemblyContaining<Drizzt>(type => type == typeof(Drizzt));
//or 
container.RegisterAssemblies(new[] { assembly1, assembly2 }, type => type == typeof(Drizzt));

Configuration

You can use the configurator parameter to configure the service registrations:

container.RegisterAssembly(assembly, configurator: context => context.WithScopedLifetime());