Unity Auto Registration

Oct 7, 2009 at 11:11 PM
Edited Oct 7, 2009 at 11:15 PM

Hi,

I used auto registration in various IoC containers before and really enjoyed it, so couldn't let my Unity projects live without it. So I have created Unity Auto Registration, and want to share it.

I have tried to cover everything I usually need and to make fluent syntax of configuring conventions more simple but yet more expressive than in other IoC containers.

Enjoy - http://autoregistration.codeplex.com/

Just as an example of how you can configure your container to auto register types:

var container = new UnityContainer();

            container
                .ConfigureAutoRegistration()
                .LoadAssemblyFrom("Plugin.dll")
                .IncludeAllLoadedAssemblies()
                .ExcludeSystemAssemblies()
                .ExcludeAssemblies(a => a.GetName().FullName.Contains("Test"))
                .Include(If.Implements<ILogger>, Then.Register().UsingPerCallMode())
                .Include(If.ImplementsITypeName, Then.Register().WithTypeName())
                .Include(If.Implements<ICustomerRepository>, Then.Register().WithName("Sample"))
                .Include(If.Implements<IOrderRepository>,
                         Then.Register().AsSingleInterfaceOfType().UsingPerCallMode())
                .Include(If.DecoratedWith<LoggerAttribute>,
                         Then.Register()
                                .AsInterface<IDisposable>()
                                .WithTypeName()
                                .UsingLifetime<MyLifetimeManager>())
                .Exclude(t => t.Name.Contains("Trace"))
                .ApplyAutoRegistration();
Mar 12, 2013 at 11:42 PM
A quick update.

Autoregistration is added to Unity in v3.0. See this post.

Grigori