本文整理汇总了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());
}
示例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);
}
示例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();
}
}
示例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);
}
示例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")));
}
示例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);
}
示例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));
}
示例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);
}
示例9: Should_return_container
public void Should_return_container()
{
var container = new UnityContainer();
var result = container.Configure(x => { });
Assert.That(result, Is.SameAs(container));
}
示例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>());
}
示例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));
}
示例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));
}
示例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>());
}
示例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>()));
}
示例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));
}