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


C# UnityContainer.Configure方法代码示例

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


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

示例1: RegisterRepositoryTypes

        public static void RegisterRepositoryTypes(UnityContainer container)
        {
            /* Register types into the container */
            container.RegisterType<IDataService, DataService>();

            //container.RegisterType<IDataService, DummyDataService>();

            /* Register the Logger to be used by all calls from the container */
            container.RegisterType<LogHelper, LogHelper>(new ContainerControlledLifetimeManager());

            /* Register our data access helper to be used uniquely for each thread call from container */
            container.RegisterType<IDataAccessor, DataAccessor>(new PerThreadLifetimeManager());

            /* Register our matching rule and call handlers (AKA Aspects) */
            container.RegisterType<IMatchingRule, AllMatchingRule>(MatchingRule);
            container.RegisterType<ICallHandler, ExceptionCallHandler>(ExceptionCallHandler.Key);
            container.RegisterType<ICallHandler, UnitOfWorkCallHandler>(UnitOfWorkCallHandler.Key);
            container.RegisterType<ICallHandler, AuthenticationCallHandler>(AuthenticationCallHandler.Key);
            container.RegisterType<ICallHandler, CommandCallHandler>(CommandCallHandler.Key);
            container.RegisterType<ICallHandler, LogCallHandler>(LogCallHandler.Key);

            /* Create a new policy and reference the matching rule and call handler by name */
            container.AddNewExtension<Interception>();
            container.Configure<Interception>()
                .AddPolicy(PolicyName)
                .AddMatchingRule(MatchingRule)
                .AddCallHandler(ExceptionCallHandler.Key)
                .AddCallHandler(UnitOfWorkCallHandler.Key)
                //.AddCallHandler(LogCallHandler.Key)
                .AddCallHandler(AuthenticationCallHandler.Key)
                .AddCallHandler(CommandCallHandler.Key);

            /* Make IDataService interface elegible for interception */
            container.Configure<Interception>().SetInterceptorFor(typeof(IDataService), new TransparentProxyInterceptor());
        }
开发者ID:okcdg,项目名称:WCF-Unity,代码行数:35,代码来源:UnityConfig.cs

示例2: InjectClassWithTwoConstructors

        public void InjectClassWithTwoConstructors()
        {
            int myInt = 37;
            string myStr = "Test";

            IUnityContainer container = new UnityContainer();

            //constructor without params
            container.Configure<InjectedMembers>().ConfigureInjectionFor<TestClass>(new InjectionConstructor());

            TestClass withOutCon = container.Resolve<TestClass>();
            Assert.IsFalse(withOutCon.StringConstructorCalled);
            Assert.IsFalse(withOutCon.IntConstructorCalled);
            //constructor with one param
            container.Configure<InjectedMembers>()
                .ConfigureInjectionFor<TestClass>("First",
                    new InjectionConstructor(myInt));

            TestClass myTestClass = container.Resolve<TestClass>("First");

            Assert.IsFalse(myTestClass.StringConstructorCalled);
            Assert.IsTrue(myTestClass.IntConstructorCalled);

            //constructor with one param
            container.Configure<InjectedMembers>()
               .ConfigureInjectionFor<TestClass>("Second",
                   new InjectionConstructor(myStr));

            TestClass myTestClass1 = container.Resolve<TestClass>("Second");
            
            Assert.IsFalse(myTestClass1.IntConstructorCalled);
            Assert.IsTrue(myTestClass1.StringConstructorCalled);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:33,代码来源:InjectedMembersFixture.cs

示例3: UsingPIABWithContainer

    static void UsingPIABWithContainer()
    {
      ConfigureLogger();
      using (var container = new UnityContainer())
      {

        container.AddNewExtension<Interception>();
        container.RegisterType<InterceptableTenantStore>(new Interceptor<TransparentProxyInterceptor>(), new InterceptionBehavior<PolicyInjectionBehavior>());

        container.Configure<Interception>().AddPolicy("logging")
             .AddMatchingRule<MemberNameMatchingRule>(
                new InjectionConstructor(
                new InjectionParameter("Save")))
             .AddCallHandler<LogCallHandler>(
                new ContainerControlledLifetimeManager(),
                new InjectionConstructor(
                  9001, true, false,
                  "This is before the method call",
                  "This is after the method call", false, false, true, 10, 1));


        var tenantStore = container.Resolve<InterceptableTenantStore>();

        // Use the interceptable type.
        Console.WriteLine("*** Invoking the Save method ***");
        tenantStore.Save();
        Console.WriteLine("*** Invoking the Modify method ***");
        tenantStore.Modify();
      }
    }
开发者ID:shahmitulv,项目名称:MelSamples,代码行数:30,代码来源:Program.cs

示例4: Can_call_method_on_concrete_after_build_up

        public void Can_call_method_on_concrete_after_build_up()
        {
            var container = new UnityContainer();
            container.Configure(x => x.AfterBuildingUp<StartableService1>().Call((c, s) => s.Start()));

            Assert.That(container.Resolve<StartableService1>().StartWasCalled);
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:7,代码来源:PostBuildUpActionTests.cs

示例5: Can_register_named_singleton_instance

        public void Can_register_named_singleton_instance()
        {
            var container = new UnityContainer();
            container.Configure(x => x.Register<IBarService, BarService>().WithName("name").AsSingleton());

            Assert.That(container.Resolve<IBarService>("name"), Is.SameAs(container.Resolve<IBarService>("name")));
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:7,代码来源:TypeRegistrationTests.cs

示例6: ConfigureContainerbyAddingExteralPolicy

 public void ConfigureContainerbyAddingExteralPolicy()
 {
     IUnityContainer container = new UnityContainer();
     container.AddNewExtension<Interception>();
     container.Configure<Interception>().AddPolicy("myRDP");
     List<InjectionPolicy> policy = new List<InjectionPolicy>(container.ResolveAll<InjectionPolicy>());
     Assert.AreEqual("myRDP", policy[1].Name);
 }
开发者ID:CFMITL,项目名称:unity,代码行数:8,代码来源:ConvenienceInterceptionAPI.cs

示例7: Can_resolve_the_container_without_registering_it

        public void Can_resolve_the_container_without_registering_it()
        {
            var container = new UnityContainer();

            container.Configure(x => { });

            Assert.That(container.Resolve<IUnityContainer>(), Is.SameAs(container));
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:8,代码来源:ExploratoryTests.cs

示例8: ConfigureAndRegisterInstance

 public void ConfigureAndRegisterInstance()
 {
     IUnityContainer container = new UnityContainer().AddNewExtension<StaticFactoryExtension>();
     IStaticFactoryConfiguration config = container.Configure<IStaticFactoryConfiguration>();
     object obj1 = container.RegisterInstance<IStaticFactoryConfiguration>(config);
     Assert.IsNotNull(config);
     Assert.IsNotNull(obj1);
 }
开发者ID:CFMITL,项目名称:unity,代码行数:8,代码来源:StaticFactoryFixture.cs

示例9: Should_return_container

        public void Should_return_container()
        {
            var container = new UnityContainer();

            var result = container.Configure(x => { });

            Assert.That(result, Is.SameAs(container));
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:8,代码来源:UnityExtensionsConfigurationTests.cs

示例10: Can_initalize_container_with_one_registry

        public void Can_initalize_container_with_one_registry()
        {
            var container = new UnityContainer();

            container.Configure(x => x.AddRegistry<FooRegistry>());

            Assert.That(container.Resolve<IFooService>(), Is.InstanceOf<FooService>());
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:8,代码来源:RegistryTests.cs

示例11: ValidationCallHandlerThrowsArgumentValidationExceptionIfValidationFailsFromConfiguration

        public void ValidationCallHandlerThrowsArgumentValidationExceptionIfValidationFailsFromConfiguration()
        {
            IUnityContainer factory = new UnityContainer().AddNewExtension<Interception>();
            factory.Configure<Interception>().SetDefaultInterceptorFor<ValidationFixtureTarget>(new TransparentProxyInterceptor());
            AddValidationPolicy(factory, string.Empty, SpecificationSource.Configuration, new TypeMatchingRule("ValidationFixtureTarget"));
            ValidationFixtureTarget target = factory.Resolve<ValidationFixtureTarget>();

            target.AcceptTest(new TestObject(false, true));
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:9,代码来源:ValidationCallHandlerFixture.cs

示例12: Can_register_a_func_with_parameters

        public void Can_register_a_func_with_parameters()
        {
            var container = new UnityContainer();

            var myService = new BarService();
            container.Configure(x => x.Register<Func<int, IBarService>>(c => i => myService));

            Assert.That(container.Resolve<Func<int, IBarService>>()(1), Is.SameAs(myService));
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:9,代码来源:TypeRegistrationTests.cs

示例13: Finds_all_registries

        public void Finds_all_registries()
        {
            var container = new UnityContainer();

            container.Configure(x => x.AddRegistry<MyRegistry>());

            Assert.That(container.Resolve<IFooService>(), Is.InstanceOf<FooService>());
            Assert.That(container.Resolve<IBarService>(), Is.InstanceOf<BarService>());
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:9,代码来源:ScanForRegistriesConventionTests.cs

示例14: Can_register_singleton

        public void Can_register_singleton()
        {
            var container = new UnityContainer();

            container.Configure(x => x.Register<IBarService, BarService>().AsSingleton());

            Assert.That(container.Resolve<IBarService>(), Is.InstanceOf<BarService>());
            Assert.That(container.Resolve<IBarService>(), Is.SameAs(container.Resolve<IBarService>()));
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:9,代码来源:TypeRegistrationTests.cs

示例15: ValidationCallHandlerDoesNothingIfValidationPasses

        public void ValidationCallHandlerDoesNothingIfValidationPasses()
        {
            IUnityContainer factory = new UnityContainer().AddNewExtension<Interception>();
            factory.Configure<Interception>().SetDefaultInterceptorFor<ValidationFixtureTarget>(new TransparentProxyInterceptor());
            AddValidationPolicy(factory, string.Empty, SpecificationSource.Attributes, new TypeMatchingRule("ValidationFixtureTarget"));
            ValidationFixtureTarget target = factory.Resolve<ValidationFixtureTarget>();

            target.AcceptTest(new TestObject(false, false));
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:9,代码来源:ValidationCallHandlerFixture.cs


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