public void Register(UnityContainer container) { container .ConfigureAutoRegistration() .Include(x => x.Assembly == Assembly.GetExecutingAssembly(), Then.Register().AsAllInterfacesOfType().UsingPerCallMode()) .ApplyAutoRegistration(); }
public static void RegisterComponents() { var container = new UnityContainer(); container.RegisterType <IProductRepository, ProductRepository>(); container.ConfigureAutoRegistration() .ExcludeSystemAssemblies() .ExcludeAssemblies(x => x.FullName.Contains(value: "NewRelic")) .ExcludeAssemblies(x => x.FullName.Contains(value: "Microsoft")) .ApplyAutoRegistration(); GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container); }
public UnityContainer Create(string namespacePrefix) { var container = new UnityContainer(); container.ConfigureAutoRegistration() .ExcludeAssemblies(assembly => !assembly.FullName.StartsWith(namespacePrefix)) .Exclude(type => !type.FullName.Contains(namespacePrefix) || !type.IsClass || type.IsAbstract) .Include( type => type.GetInterfaces().Length > 0, Then.Register().AsAllInterfacesOfType().UsingSingletonMode()) .Include( type => type.GetInterfaces().Length > 0, Then.Register().WithTypeName().UsingSingletonMode()) .ApplyAutoRegistration(); InitAware(container); return(container); }
private void Example() { var container = new UnityContainer(); container .ConfigureAutoRegistration() .LoadAssemblyFrom("MyFancyPlugin.dll") .ExcludeSystemAssemblies() .ExcludeAssemblies(a => a.GetName().FullName.Contains("Test")) .Include(If.ImplementsSingleInterface, Then.Register().AsSingleInterfaceOfType().UsingSingletonMode()) .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>() .WithPartName(WellKnownAppParts.Logger) .UsingLifetime <MyLifetimeManager>()) .Exclude(t => t.Name.Contains("Trace")) .ApplyAutoRegistration(); }
internal static void AutoRegister() { _unityContainer.ConfigureAutoRegistration() .Include(type => type.ImplementsOpenGeneric(typeof(IMapper <,>)), Then.Register().AsFirstInterfaceOfType().WithPartName("Mapper")) .ApplyAutoRegistration(); }