当前位置: 首页>>代码示例>>C#>>正文


C# UnityContainer.ConfigureAutoRegistration方法代码示例

本文整理汇总了C#中Microsoft.Practices.Unity.UnityContainer.ConfigureAutoRegistration方法的典型用法代码示例。如果您正苦于以下问题:C# UnityContainer.ConfigureAutoRegistration方法的具体用法?C# UnityContainer.ConfigureAutoRegistration怎么用?C# UnityContainer.ConfigureAutoRegistration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Practices.Unity.UnityContainer的用法示例。


在下文中一共展示了UnityContainer.ConfigureAutoRegistration方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Register

 public void Register(UnityContainer container)
 {
     container
         .ConfigureAutoRegistration()
         .Include(x => x.Assembly == Assembly.GetExecutingAssembly(), Then.Register().AsAllInterfacesOfType().UsingPerCallMode())
         .ApplyAutoRegistration();
 }
开发者ID:swmal,项目名称:DiIocDemo,代码行数:7,代码来源:RegisterAllModule.cs

示例2: CanMakeBusinessProcessWithAssemblyInclusion

        public void CanMakeBusinessProcessWithAssemblyInclusion()
        {
            UnityContainer container = new UnityContainer();
            container.ConfigureAutoRegistration().
                // include just the target assembly.
                 Include(t => InTargetAssembly(t),
                    Then.Register().AsAllInterfacesOfType()).
                ApplyAutoRegistration();

            BusinessProcess businessProcess = container.Resolve<BusinessProcess>();

            Assert.IsNotNull(businessProcess);
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:13,代码来源:UnityTest.cs

示例3: CanGetAllValidators

        public void CanGetAllValidators()
        {
            UnityContainer container = new UnityContainer();
            container.ConfigureAutoRegistration().
                Include(t => InTargetAssembly(t),
                Then.Register().AsAllInterfacesOfType()).
                Include(If.Implements<IValidator>, Then.Register().As<IValidator>().WithTypeName()).
                ApplyAutoRegistration();

            var validators = container.ResolveAll<IValidator>();

            Assert.IsNotNull(validators);
            Assert.AreEqual(3, validators.Count());
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:14,代码来源:UnityTest.cs

示例4: CanFilterOutValidatorRegistrations

        public void CanFilterOutValidatorRegistrations()
        {
            UnityContainer container = new UnityContainer();
            container.ConfigureAutoRegistration().
                Include(t => InTargetAssembly(t),
                Then.Register().AsAllInterfacesOfType()).
                Exclude(If.Is<FailValidator>).
                Include(If.Implements<IValidator>, Then.Register().As<IValidator>().WithTypeName()).
                ApplyAutoRegistration();

            // excluding the FailValidator should leave 2 of them
            var validators = container.ResolveAll<IValidator>();

            Assert.IsNotNull(validators);
            Assert.AreEqual(2, validators.Count());
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:16,代码来源:UnityTest.cs

示例5: CanMakeBusinessProcessWithAssemblyExclusion

        public void CanMakeBusinessProcessWithAssemblyExclusion()
        {
            UnityContainer container = new UnityContainer();
            container.ConfigureAutoRegistration().
                Include(t => true,
                    Then.Register().AsAllInterfacesOfType()).

                // exclude system and library assemblies
                ExcludeSystemAssemblies().
                ExcludeAssemblies(a => IsLibraryAssembly(a)).

                ApplyAutoRegistration();

            BusinessProcess businessProcess = container.Resolve<BusinessProcess>();

            Assert.IsNotNull(businessProcess);
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:17,代码来源:UnityTest.cs

示例6: UnityAutoRegistration

        private static void UnityAutoRegistration()
        {
            // Register
            var container = new UnityContainer();

            container
                .ConfigureAutoRegistration()
                .LoadAssemblyFrom(typeof(ICourseRepository).Assembly.Location)
                .LoadAssemblyFrom(typeof(ICourseAppService).Assembly.Location)
                .LoadAssemblyFrom(typeof(SqlCourseRepository).Assembly.Location)
                .Include(If.ImplementsITypeName, Then.Register())
                .ExcludeSystemAssemblies()
                .ApplyAutoRegistration();

            // Resolve
            var svc = container.Resolve<ICourseAppService>();
            var descriptions = svc.GetCourseDescriptions(new int[] { 10, 20, 30 });

            Console.WriteLine(descriptions);
            Console.ReadLine();
        }
开发者ID:fanshu,项目名称:CoursewareDI,代码行数:21,代码来源:Program.cs

示例7: CanMakeSingletonInstance

        public void CanMakeSingletonInstance()
        {
            UnityContainer container = new UnityContainer();
            container.ConfigureAutoRegistration().
                Include(t => t != typeof(BusinessProcess),
                    Then.Register().AsAllInterfacesOfType()).
                Include(t => t == typeof(BusinessProcess),
                    Then.Register().AsSelf().UsingSingletonMode()).

                // exclude system and library assemblies
                ExcludeSystemAssemblies().
                ExcludeAssemblies(a => IsLibraryAssembly(a)).

                ApplyAutoRegistration();

            BusinessProcess businessProcess1 = container.Resolve<BusinessProcess>();
            BusinessProcess businessProcess2 = container.Resolve<BusinessProcess>();

            Assert.AreSame(businessProcess1, businessProcess2);
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:20,代码来源:UnityTest.cs

示例8: CanMakeTransientInstance

        public void CanMakeTransientInstance()
        {
            UnityContainer container = new UnityContainer();
            container.ConfigureAutoRegistration().
                Include(t => true,
                    Then.Register().AsAllInterfacesOfType()).

                // exclude system and library assemblies
                ExcludeSystemAssemblies().
                ExcludeAssemblies(a => IsLibraryAssembly(a)).

                ApplyAutoRegistration();

            BusinessProcess businessProcess1 = container.Resolve<BusinessProcess>();
            BusinessProcess businessProcess2 = container.Resolve<BusinessProcess>();

            Assert.AreNotSame(businessProcess1, businessProcess2);
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:18,代码来源:UnityTest.cs

示例9: Example

        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();
        }
开发者ID:kevinwiegand,项目名称:EnergyTrading-Core,代码行数:23,代码来源:AutoRegistrationFixture.cs


注:本文中的Microsoft.Practices.Unity.UnityContainer.ConfigureAutoRegistration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。