Search
Install from Nuget
Add it to your project with nuget: Install-Package UnityAutoRegistration
http://nuget.org/List/Packages/UnityAutoRegistration

Project Description
Unity Auto Registration extends Unity IoC container and provides fluent syntax to configure rules for automatic type registration. Using few code lines you can scan specified assemblies and register all types that satisfy your rules.

Rules for determining whether to include/exclude type/assembly are predicates (Predicate<T>) so you can use lambda syntax to specify them or direct method name. There are a few methods in If helper class (like Implements, DecoratedWith) to cover some common scenarios of type registering.

For example, auto registration configuration using Unity Auto Registration may look like:
            var container = new UnityContainer();

            container
                .ConfigureAutoRegistration()
                .LoadAssemblyFrom("MyFancyPlugin.dll")
                .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()
                                .As<IDisposable>()
                                .WithTypeName()
                                .UsingLifetime<MyLifetimeManager>())
                .Exclude(t => t.Name.Contains("Trace"))
                .ApplyAutoRegistration();
Last edited Jul 21 2011 at 5:05 AM by ArtemGovorov, version 10
Updating...
© 2006-2012 Microsoft | Get Help | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2012.1.11.18365