本文整理汇总了C#中UnityContainer.Configure方法的典型用法代码示例。如果您正苦于以下问题:C# UnityContainer.Configure方法的具体用法?C# UnityContainer.Configure怎么用?C# UnityContainer.Configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityContainer
的用法示例。
在下文中一共展示了UnityContainer.Configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanSetUpAPolicyWithExternallyConfiguredRulesAndHandlers
public void CanSetUpAPolicyWithExternallyConfiguredRulesAndHandlers()
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container
.Configure<Interception>()
.AddPolicy("policy1")
.AddMatchingRule("rule1")
.AddCallHandler("handler1")
.AddCallHandler("handler2").Interception.Container
.RegisterType<IMatchingRule, AlwaysMatchingRule>("rule1")
.RegisterType<ICallHandler, GlobalCountCallHandler>(
"handler1",
new InjectionConstructor("handler1"))
.RegisterType<ICallHandler, GlobalCountCallHandler>(
"handler2",
new InjectionConstructor("handler2"),
new InjectionProperty("Order", 10));
GlobalCountCallHandler.Calls.Clear();
container
.Configure<Interception>()
.SetInterceptorFor<Wrappable>("wrappable", new VirtualMethodInterceptor());
Wrappable wrappable1 = container.Resolve<Wrappable>("wrappable");
wrappable1.Method2();
Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler1"]);
Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler2"]);
}
示例2: CanConfigureRemotingInterceptionOnInterface
public void CanConfigureRemotingInterceptionOnInterface()
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container.Configure<Interception>().SetInterceptorFor<Interface>(new TransparentProxyInterceptor());
}
示例3: CanAddExtensionWithNonDefaultConstructor
public void CanAddExtensionWithNonDefaultConstructor()
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<ContainerExtensionWithNonDefaultConstructor>();
var extension = container.Configure(typeof (ContainerExtensionWithNonDefaultConstructor));
Assert.IsNotNull(extension);
}
示例4: CanConfigureDefaultRemotingInterceptionOnMBRO
public void CanConfigureDefaultRemotingInterceptionOnMBRO()
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container.Configure<Interception>()
.SetDefaultInterceptorFor<Wrappable>(new TransparentProxyInterceptor());
}
示例5: CanGetExtensionConfigurationFromContainer
public void CanGetExtensionConfigurationFromContainer()
{
IUnityContainer container = new UnityContainer()
.AddNewExtension<StaticFactoryExtension>();
IStaticFactoryConfiguration config = container.Configure<IStaticFactoryConfiguration>();
Assert.IsNotNull(config);
}
示例6: CanLookupExtensionByClassName
public void CanLookupExtensionByClassName()
{
MockContainerExtension extension = new MockContainerExtension();
IUnityContainer container = new UnityContainer();
container.AddExtension(extension);
MockContainerExtension result = container.Configure<MockContainerExtension>();
Assert.AreSame(extension, result);
}
示例7: CanGetConfigurationWithoutGenericMethod
public void CanGetConfigurationWithoutGenericMethod()
{
MockContainerExtension extension = new MockContainerExtension();
IUnityContainer container = new UnityContainer()
.AddExtension(extension);
IMockConfiguration config = (IMockConfiguration)container.Configure(typeof(IMockConfiguration));
Assert.AreSame(extension, config);
Assert.AreSame(container, config.Container);
}
示例8: CanGetConfigurationInterfaceFromExtension
public void CanGetConfigurationInterfaceFromExtension()
{
MockContainerExtension extension = new MockContainerExtension();
IUnityContainer container = new UnityContainer()
.AddExtension(extension);
IMockConfiguration config = container.Configure<IMockConfiguration>();
Assert.AreSame(extension, config);
Assert.AreSame(container, config.Container);
}
示例9: SettingUpRuleWithEmptyNameThrows
public void SettingUpRuleWithEmptyNameThrows()
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
try
{
container.Configure<Interception>().AddPolicy(string.Empty);
Assert.Fail("should have thrown");
}
catch (ArgumentException)
{
}
}
示例10: ConfiguringRemotingInterceptionOnNonMBROTypeThrows
public void ConfiguringRemotingInterceptionOnNonMBROTypeThrows()
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
try
{
container.Configure<Interception>()
.SetInterceptorFor<WrappableThroughInterface>(new TransparentProxyInterceptor());
Assert.Fail("Call to SetInjectorFor<T>() should have thrown");
}
catch (ArgumentException)
{
// expected exception
}
}
示例11: CanSetUpAnEmptyRule
public void CanSetUpAnEmptyRule()
{
// there is no visible effect for this, but it should still be resolved.
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
// empty
container
.Configure<Interception>()
.AddPolicy("policy1");
List<InjectionPolicy> policies
= new List<InjectionPolicy>(container.ResolveAll<InjectionPolicy>());
Assert.AreEqual(2, policies.Count);
Assert.IsInstanceOfType(policies[0], typeof(AttributeDrivenPolicy));
Assert.IsInstanceOfType(policies[1], typeof(RuleDrivenPolicy));
Assert.AreEqual("policy1", policies[1].Name);
}
示例12: CanSetUpInterceptorThroughInjectionMember
public void CanSetUpInterceptorThroughInjectionMember()
{
CallCountHandler handler = new CallCountHandler();
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container.Configure<Interception>()
.AddPolicy("policy")
.AddMatchingRule<AlwaysMatchingRule>()
.AddCallHandler(handler);
container.RegisterType<IInterface, BaseClass>(
"test",
new Interceptor<InterfaceInterceptor>(),
new InterceptionBehavior<PolicyInjectionBehavior>());
IInterface instance = container.Resolve<IInterface>("test");
instance.DoSomething("1");
Assert.AreEqual(1, handler.CallCount);
}
示例13: SettingUpAPolicyWithANullRuleElementThrows
public void SettingUpAPolicyWithANullRuleElementThrows()
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
try
{
container
.Configure<Interception>()
.AddPolicy("policy1")
.AddMatchingRule(typeof(AlwaysMatchingRule))
.AddMatchingRule((string)null)
.AddCallHandler(new CallCountHandler());
Assert.Fail("Should have thrown");
}
catch (ArgumentException)
{
}
}
示例14: CanSetUpAPolicyWithLifetimeManagedNamedInjectedRulesAndHandlers
public void CanSetUpAPolicyWithLifetimeManagedNamedInjectedRulesAndHandlers()
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container
.Configure<Interception>()
.AddPolicy("policy1")
.AddMatchingRule<AlwaysMatchingRule>(
"rule1",
new ContainerControlledLifetimeManager())
.AddCallHandler<CallCountHandler>(
"handler1",
(LifetimeManager)null)
.AddCallHandler<CallCountHandler>(
"handler2",
new ContainerControlledLifetimeManager(),
new InjectionProperty("Order", 10));
GlobalCountCallHandler.Calls.Clear();
container
.Configure<Interception>()
.SetInterceptorFor<Wrappable>("wrappable", new TransparentProxyInterceptor());
Wrappable wrappable1 = container.Resolve<Wrappable>("wrappable");
wrappable1.Method2();
CallCountHandler handler1 = (CallCountHandler)container.Resolve<ICallHandler>("handler1");
CallCountHandler handler2 = (CallCountHandler)container.Resolve<ICallHandler>("handler2");
Assert.AreEqual(0, handler1.CallCount); // not lifetime maanaged
Assert.AreEqual(1, handler2.CallCount); // lifetime managed
}
示例15: CanSetUpAPolicyWithNamedInjectedRulesAndHandlers
public void CanSetUpAPolicyWithNamedInjectedRulesAndHandlers()
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container
.Configure<Interception>()
.AddPolicy("policy1")
.AddMatchingRule<AlwaysMatchingRule>("rule1")
.AddCallHandler<GlobalCountCallHandler>(
"handler1",
new InjectionConstructor("handler1"))
.AddCallHandler<GlobalCountCallHandler>(
"handler2",
new InjectionConstructor("handler2"),
new InjectionProperty("Order", 10));
GlobalCountCallHandler.Calls.Clear();
container
.Configure<Interception>()
.SetInterceptorFor<Wrappable>("wrappable", new TransparentProxyInterceptor());
Wrappable wrappable1 = container.Resolve<Wrappable>("wrappable");
wrappable1.Method2();
GlobalCountCallHandler handler1 = (GlobalCountCallHandler)container.Resolve<ICallHandler>("handler1");
GlobalCountCallHandler handler2 = (GlobalCountCallHandler)container.Resolve<ICallHandler>("handler2");
Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler1"]);
Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler2"]);
Assert.AreEqual(0, handler1.Order);
Assert.AreEqual(10, handler2.Order);
}