本文整理汇总了C#中IUnityContainer.Configure方法的典型用法代码示例。如果您正苦于以下问题:C# IUnityContainer.Configure方法的具体用法?C# IUnityContainer.Configure怎么用?C# IUnityContainer.Configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUnityContainer
的用法示例。
在下文中一共展示了IUnityContainer.Configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureContainer
protected override void ConfigureContainer(IUnityContainer container)
{
BetamaxSettings settings = null;
var recorder = container.Configure<BetamaxRecorder>();
if (recorder != null)
{
settings = recorder.Settings;
}
else
{
var player = container.Configure<BetamaxPlayer>();
if (player != null)
{
settings = player.Settings;
}
}
if (settings == null)
return;
if (!string.IsNullOrEmpty(Tapes))
{
settings.TapesLocation = Tapes;
}
InterestingInterfaces.ForEach(interesting => interesting.ConfigureContainer(settings));
}
示例2: RegisterTypes
public static void RegisterTypes(IUnityContainer container)
{
string[] assemblyNameParts = Assembly.GetExecutingAssembly().GetName().Name.Split('.');
string assemblyPrefix = string.Join(".", assemblyNameParts, 0, 1);
container.AddNewExtension<Interception>();
Predicate<Type> intercept = (t) =>
{
var interceptionConfiguration = container.Configure<Interception>();
if (t.IsConcrete() && !t.IsSealed && hasAttribute(t, typeof(LogAttribute)))
{
interceptionConfiguration.SetDefaultInterceptorFor(t, new VirtualMethodInterceptor());
}
return true;
};
Predicate<Assembly> includeAssembly = (a) =>
{
var assemblyName = a.GetName().Name;
return assemblyName.StartsWith(assemblyPrefix) && (assemblyName.Contains("Business") || assemblyName.Contains("Data"));
};
container.Configure(c =>
{
c.Scan(scan =>
{
scan.AssembliesInBaseDirectory(a => includeAssembly(a));
scan.Include(t => intercept(t));
scan.WithNamingConvention();
});
c.Configure<IDatabaseControlContext>().Using<HttpContextLifetimeManager<IDatabaseControlContext>>();
});
}
示例3: RegisterDependencies
/// <summary>
/// Additionally configures unity container with classes in Database access project
/// </summary>
/// <param name="container">Unity container instance</param>
public static void RegisterDependencies(IUnityContainer container)
{
container.RegisterType<IServiceBehavior, UmaConnNHibernateBehavior>("nHibernate");
container.RegisterInstance<ISessionFactory>(UmaConnNhibernateFactory.Instance, new ContainerControlledLifetimeManager());
container.RegisterType<ISession>(
new HierarchicalLifetimeManager(),
new InjectionFactory(c => container.Resolve<ISessionFactory>().OpenSession()));
container.RegisterType<IUmaMasterDataService, UmaMasterDataService>();
container.RegisterType<ICallHandler, UmaConnTransactionHandler>("TransactionHandler");
container.AddNewExtension<Interception>();
container.Configure<Interception>().SetInterceptorFor<UmaMasterDataService>(new TransparentProxyInterceptor());
// These extensions will handle cases where
// ILog is resolved as Property with [Dependency] attribute.
// Will create Logger with name of resolving Type.
// http://blog.baltrinic.com/software-development/dotnet/log4net-integration-with-unity-ioc-container
container
.AddNewExtension<BuildTracking>()
.AddNewExtension<LogCreation>();
// DO NOT DELETE THIS CODE UNLESS WE NO LONGER REQUIRE ASSEMBLY NLOG.EXTENDED!!!
var dummyCall = typeof(NLog.Web.NLogHttpModule);
var ok = dummyCall.Assembly.CodeBase;
}
示例4: RegisterInterceptor
/// <summary>
/// Actually register the interceptor against this type.
/// </summary>
/// <param name="container">Container to configure.</param>
/// <param name="interceptor">interceptor to register.</param>
internal override void RegisterInterceptor(IUnityContainer container, IInterceptor interceptor)
{
var typeInterceptor = interceptor as ITypeInterceptor;
if (typeInterceptor != null)
{
container.Configure<Interception>().SetInterceptorFor(
this.ResolvedType, this.Name,
typeInterceptor);
}
else
{
container.Configure<Interception>().SetInterceptorFor(
this.ResolvedType, this.Name,
(IInstanceInterceptor)interceptor);
}
}
示例5: InitializeContainer
private void InitializeContainer()
{
container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<BusinessLogic.BankAccount>(
new InterceptionBehavior<PolicyInjectionBehavior>(),
new Interceptor<TransparentProxyInterceptor>());
container.Configure<Interception>()
.AddPolicy("policy-updates")
.AddMatchingRule<TypeMatchingRule>(
new InjectionConstructor(
new InjectionParameter(typeof(BusinessLogic.BankAccount))))
.AddMatchingRule<MemberNameMatchingRule>(
new InjectionConstructor(
new InjectionParameter(new string[] { "Deposit", "Withdraw" })))
.AddCallHandler<TraceCallHandler>(
new ContainerControlledLifetimeManager(),
new InjectionConstructor(
new TraceSource("interception-updates")))
.Interception
.AddPolicy("policy-query")
.AddMatchingRule<TypeMatchingRule>(
new InjectionConstructor(
new InjectionParameter(typeof(BusinessLogic.BankAccount))))
.AddMatchingRule<MemberNameMatchingRule>(
new InjectionConstructor("GetCurrentBalance"))
.AddCallHandler<TraceCallHandler>(
new ContainerControlledLifetimeManager(),
new InjectionConstructor(
new TraceSource("interception-queries")));
}
示例6: IsTypeRegistered
/// <summary>
/// Evaluates if a specified type was registered in the container.
/// </summary>
/// <param name="container">The container to check if the type was registered in.</param>
/// <param name="type">The type to check if it was registered.</param>
/// <returns><see langword="true" /> if the <paramref name="type"/> was registered with the container.</returns>
/// <remarks>
/// In order to use this extension, you must first call <see cref="IUnityContainer.AddNewExtension{TExtension}"/>
/// and specify <see cref="UnityContainerExtension"/> as the extension type.
/// </remarks>
public static bool IsTypeRegistered(IUnityContainer container, Type type)
{
var extension = container.Configure<UnityIsTypeRegisteredExtension>();
// The extension wasn't registered in the container, so we can't determine
// if the type is registered or not.
if (extension == null) return false;
return extension.Context.Policies.Get<IBuildKeyMappingPolicy>(new NamedTypeBuildKey(type)) != null;
}
示例7: IsTypeRegistered
/// <summary>
/// Evaluates if a specified type was registered in the container.
/// </summary>
/// <param name="container">The container to check if the type was registered in.</param>
/// <param name="type">The type to check if it was registered.</param>
/// <returns><see langword="true" /> if the <paramref name="type"/> was registered with the container.</returns>
/// <remarks>
/// In order to use this extension, you must first call <see cref="UnityContainerExtensions.AddNewExtension{TExtension}"/>
/// and specify <see cref="UnityContainerExtension"/> as the extension type.
/// </remarks>
public static bool IsTypeRegistered(IUnityContainer container, Type type)
{
var extension = container.Configure<UnityBootstrapperExtension>();
if (extension == null) {
//Extension was not added to the container.
return false;
}
var policy = extension.Context.Policies.Get<IBuildKeyMappingPolicy>(new NamedTypeBuildKey(type));
return policy != null;
}
示例8: Setup
public void Setup()
{
container = new UnityContainer();
container.RegisterType<ICallHandler, MyCallHandler>("MyHandler", new ContainerControlledLifetimeManager());
container.AddNewExtension<Interception>();
container.Configure<Interception>()
.AddPolicy("My Policy")
.AddMatchingRule(new AlwaysMatchingRule())
.AddCallHandler("MyHandler");
}
示例9: IsRegistered
public static bool IsRegistered(IUnityContainer container, Type type)
{
InternalUnityExtension extension = container.Configure<InternalUnityExtension>();
IBuildKeyMappingPolicy policy = null;
if (extension != null)
{
policy = extension.Context.Policies.Get<IBuildKeyMappingPolicy>(new NamedTypeBuildKey(type));
}
return policy != null;
}
示例10: UnityProvider
public UnityProvider(IDictionary<Type, object> map, int dbRetries, int dbSleepSeconds)
{
IMatchingRule alwaysMatch = new AlwaysMatchingRule();
_map = map;
_container = new UnityContainer();
_retries = dbRetries;
_sleepSeconds = dbSleepSeconds;
IDictionary<Type, RetryOrHandleExceptionDelgate> exceptionTranslators = GetExceptionTranslators(map);
_container.AddNewExtension<Interception>();
Interception inter = _container.Configure<Interception>();
if (inter == null)
{
Trace.WriteLine("No interception");
}
PolicyDefinition definition = inter.AddPolicy("DbRetry");
if (definition == null)
{
Trace.WriteLine("No policy definition 0");
}
if (definition.AddMatchingRule(alwaysMatch) == null)
{
Trace.WriteLine("No policy definition 1");
}
_interceptor = new DbRetryInterceptor(dbRetries, dbSleepSeconds, exceptionTranslators);
if (definition.AddCallHandler(_interceptor) == null)
{
Trace.WriteLine("No policy definition 2");
}
IInstanceInterceptor _instanceInterceptor = new InterfaceInterceptor();
foreach (KeyValuePair<Type, object> entry in map)
{
_container.RegisterInstance(entry.Key, entry.Value);
if (entry.Key.IsInterface)
{
_container.Configure<Interception>().SetInterceptorFor(entry.Key, _instanceInterceptor);
}
}
}
示例11: RegisterNHibernateStuff
private void RegisterNHibernateStuff(IUnityContainer container)
{
container.RegisterInstance<ISessionFactory>(CreateSessionFactory());
container.RegisterType<ISession>(new RequestContextLifeTimeManager(typeof(ISession)));
container.Configure<StaticFactoryExtension>()
.RegisterFactory<ISession>(c => c.Resolve<ISessionFactory>().GetCurrentSession());
container.RegisterType<IRepository, NHibernateRepository>();
container.RegisterType<IUnitOfWorkProvider, NHibernateUnitOfWorkProvider>();
}
示例12: ConfigureNHibernateRepositories
private static void ConfigureNHibernateRepositories(IUnityContainer container)
{
container.RegisterType<ILocationRepository, LocationRepository>();
container.RegisterType<ICargoRepository, CargoRepository>();
container.AddNewExtension<Interception>();
container.Configure<Interception>()
.SetInterceptorFor<IBookingService>(new InterfaceInterceptor())
.SetInterceptorFor<IHandlingEventService>(new InterfaceInterceptor())
.AddPolicy("Transactions")
.AddCallHandler<TransactionCallHandler>()
.AddMatchingRule(new AssemblyMatchingRule("DDDSample.Application"));
}
示例13: RegisterIfMissing
/// <summary>
/// Helper method that registers <see cref="TypeRegistrationTrackerExtension"/> extensions
/// in the Unity container if not previously registered.
/// </summary>
/// <param name="container">Target container.</param>
public static void RegisterIfMissing(IUnityContainer container)
{
var extension = container.Configure<TypeRegistrationTrackerExtension>();
if (extension == null)
container.AddNewExtension<TypeRegistrationTrackerExtension>();
}
示例14: ConfigureContainer
internal void ConfigureContainer(IUnityContainer container)
{
PolicyDefinition policyDefinition = container.Configure<Interception>().AddPolicy(this.Name);
foreach (var matchingRuleElement in this.MatchingRules)
{
matchingRuleElement.Configure(container, policyDefinition);
}
foreach (var callHandlerElement in this.CallHandlers)
{
callHandlerElement.Configure(container, policyDefinition);
}
}
示例15: AddExceptionPolicy
void AddExceptionPolicy(IUnityContainer factory,
string exceptionPolicyName,
params IMatchingRule[] rules)
{
var policy = factory.Configure<Interception>().AddPolicy("Noop");
foreach (var rule in rules)
{
policy.AddMatchingRule(rule);
}
policy.AddCallHandler(
typeof(ExceptionCallHandler),
new InjectionConstructor(new ResolvedParameter<ExceptionPolicyImpl>(exceptionPolicyName)));
}