jessyhoule icon

C# Unity / Convention Based Registration

jessyhoule | PRO | 09/18/15 05:50:37 AM UTC | 0 ⭐ | 219 👁️ | Never ⏰ | []
C# |

660 B

|

None

|

0 👍

/

0 👎

using (var container = new UnityContainer())
{
    container.ConfigureAutoRegistration()
         .LoadAssemblyFrom(typeof(ITest).Assembly.Location)
         .LoadAssemblyFrom(typeof(Test).Assembly.Location)
         .Include(If.ImplementsITypeName, Then.Register())
         .ApplyAutoRegistration();
}
         
// Set up registration by convention.
// http://blogs.msdn.com/b/agile/archive/2013/03/12/unity-configuration-registration-by-convention.aspx
 
using (var container = new UnityContainer())
{
    container.RegisterTypes(
        AllClasses.FromAssembliesInBasePath(),
        WithMappings.FromMatchingInterface,
        WithName.Default,
        WithLifetime.ContainerControlled);
}

Comments