Exemplo n.º 1
0
 public void Register(UnityContainer container)
 {
     container
         .ConfigureAutoRegistration()
         .Include(x => x.Assembly == Assembly.GetExecutingAssembly(), Then.Register().AsAllInterfacesOfType().UsingPerCallMode())
         .ApplyAutoRegistration();
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
 internal static void  AutoRegister()
 {
     _unityContainer.ConfigureAutoRegistration()
     .Include(type => type.ImplementsOpenGeneric(typeof(IMapper <,>)), Then.Register().AsFirstInterfaceOfType().WithPartName("Mapper"))
     .ApplyAutoRegistration();
 }