本文整理汇总了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();
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}