本文整理汇总了C#中ContainerBuilder.EnableCompositionIntegration方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.EnableCompositionIntegration方法的具体用法?C# ContainerBuilder.EnableCompositionIntegration怎么用?C# ContainerBuilder.EnableCompositionIntegration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.EnableCompositionIntegration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AutofacCanResolveMefComponentRegisteredUsingAddExportedValueTest
public void AutofacCanResolveMefComponentRegisteredUsingAddExportedValueTest()
{
MefSingletonComponent.Counter = 0;
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Register catalog and types
builder.RegisterCatalog(assemblyCatalog);
var autofacContainer = builder.Build();
var compositionContainer = autofacContainer.Resolve<CompositionContainer>();
var batch = new CompositionBatch();
var singletonComponent = new MefSingletonComponent();
batch.AddExportedValue(singletonComponent);
compositionContainer.Compose(batch);
var singletonComponent1 = compositionContainer.GetExport<MefSingletonComponent>().Value;
Assert.That(MefSingletonComponent.Counter, Is.EqualTo(1));
Assert.That(singletonComponent1, Is.SameAs(singletonComponent));
var singletonComponent2 = autofacContainer.Resolve<MefSingletonComponent>();
Assert.That(MefSingletonComponent.Counter, Is.EqualTo(1));
Assert.That(singletonComponent2, Is.SameAs(singletonComponent));
}
示例2: AutofacCanResolveMefComponentRegisteredByTypeUsingConstructorInjectionTest
public void AutofacCanResolveMefComponentRegisteredByTypeUsingConstructorInjectionTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Add composition support for autofac
builder.EnableCompositionIntegration();
builder.RegisterCatalog(assemblyCatalog);
builder.RegisterType<AutofacComponent1>().As<IAutofacComponent>();
var autofacContainer = builder.Build();
var autofacComponent = autofacContainer.Resolve<IAutofacComponent>();
Assert.That(autofacComponent, Is.Not.Null);
Assert.That(autofacComponent.MefComponent.GetType(), Is.EqualTo(typeof(MefComponent1)));
}
示例3: ConfigureMefThenAutofac
private static IContainer ConfigureMefThenAutofac()
{
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
builder.RegisterCatalog(catalog);
builder.RegisterType<AutofacComponent>().As<IAutofacComponent>();
builder.RegisterType<CountableAutofacComponent>().As<ICountableAutofacComponent>();
return builder.Build();
}
示例4: AutofacCanResolveMefComponentRegisteredByTypeAndRegistrationNameTest
public void AutofacCanResolveMefComponentRegisteredByTypeAndRegistrationNameTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Add composition support for autofac
builder.EnableCompositionIntegration();
builder.RegisterCatalog(assemblyCatalog);
builder.Register((c, p) => new AutofacComponent2(c.ResolveNamed<IMefComponent>("component2"))).As<IAutofacComponent>();
var autofacContainer = builder.Build();
var mefComponent = autofacContainer.ResolveNamed<IMefComponent>("component2");
Assert.That(mefComponent, Is.Not.Null);
Assert.That(mefComponent.GetType(), Is.EqualTo(typeof(MefComponent2)));
var autofacComponent = autofacContainer.Resolve<IAutofacComponent>();
Assert.That(autofacComponent, Is.Not.Null);
Assert.That(autofacComponent.MefComponent.GetType(), Is.EqualTo(typeof(MefComponent2)));
}
示例5: EnableCompositionIntegration
/// <summary>
/// Enables Managed Extensibility Framework two-way integration.
/// </summary>
/// <param name = "container">Target container.</param>
/// <returns>
/// <see cref = "CompositionIntegration" /> instance.
/// </returns>
public static CompositionIntegration EnableCompositionIntegration(this IComponentContext container)
{
lock (container)
{
if (!container.IsRegistered<CompositionIntegration>())
{
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
builder.Update(container.ComponentRegistry);
}
return container.Resolve<CompositionIntegration>();
}
}
示例6: AutofacCanResolveAutofacComponentThatHasAutofacAndMefDependenciesTest
public void AutofacCanResolveAutofacComponentThatHasAutofacAndMefDependenciesTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Register catalog and types
builder.RegisterCatalog(assemblyCatalog);
builder.RegisterType<AutofacOnlyComponent1>().As<IAutofacOnlyComponent>();
builder.RegisterType<AutofacMixedComponent>();
// Test
var container = builder.Build();
var autofacMixedComponent = container.Resolve<AutofacMixedComponent>();
Assert.That(autofacMixedComponent, Is.Not.Null);
Assert.That(autofacMixedComponent.GetType(), Is.EqualTo(typeof (AutofacMixedComponent)));
Assert.That(autofacMixedComponent.MefComponent.GetType(), Is.EqualTo(typeof (MefComponent1)));
Assert.That(autofacMixedComponent.AutofacComponent.GetType(), Is.EqualTo(typeof (AutofacOnlyComponent1)));
}
示例7: DisposingAutofacDisposesCompositionContainerTest
public void DisposingAutofacDisposesCompositionContainerTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Add composition support for autofac
builder.EnableCompositionIntegration();
builder.RegisterCatalog(assemblyCatalog);
var autofacContainer = builder.Build();
var compositionContainer = autofacContainer.Resolve<CompositionContainer>();
autofacContainer.Dispose();
Assert.That(delegate
{
compositionContainer.GetExport<IMefComponent>();
}, Throws.TypeOf<ObjectDisposedException>());
}
示例8: AutofacCanResolveMultipleMefInstancesTest
public void AutofacCanResolveMultipleMefInstancesTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Add composition support for autofac
builder.EnableCompositionIntegration();
builder.RegisterCatalog(assemblyCatalog);
var autofacContainer = builder.Build();
Assert.That(delegate
{
var defaultInstance = autofacContainer.Resolve<IMultipleMefComponent>();
Debug.WriteLine("Default Instance -> {0}", defaultInstance);
var all = autofacContainer.Resolve<IEnumerable<IMultipleMefComponent>>().ToArray();
Debug.WriteLine("All instances -> {0}, {1}", all);
}, Throws.Nothing);
}
示例9: AutofacCanResolveCompositionContainerTest
public void AutofacCanResolveCompositionContainerTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Add composition support for autofac
builder.EnableCompositionIntegration();
builder.RegisterCatalog(assemblyCatalog);
var autofacContainer = builder.Build();
var compositionContainer = autofacContainer.Resolve<CompositionContainer>();
Assert.That(compositionContainer, Is.Not.Null);
}
示例10: AutofacDoesNotSatisfyMefImportsOnAutofacComponentsWhenMarkedWithPartNotComposableAttributeTest
public void AutofacDoesNotSatisfyMefImportsOnAutofacComponentsWhenMarkedWithPartNotComposableAttributeTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Add composition support for autofac
builder.EnableCompositionIntegration();
builder.RegisterCatalog(assemblyCatalog);
builder.Register((c, p) => new AutofacComponent3(c.ResolveNamed<IMefComponent>("component2"))).As<IAutofacComponent>();
var autofacContainer = builder.Build();
var autofacComponent = autofacContainer.Resolve<IAutofacComponent>();
Assert.That(autofacComponent, Is.Not.Null);
Assert.That(autofacComponent.ImportedMefComponent, Is.Null);
}
示例11: AutofacLazySatisfiesMefImportsByTypeOnAutofacComponentsTest
public void AutofacLazySatisfiesMefImportsByTypeOnAutofacComponentsTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Add composition support for autofac
builder.EnableCompositionIntegration();
builder.RegisterCatalog(assemblyCatalog);
builder.RegisterType<AutofacComponent1>().As<IAutofacComponent>();
builder.RegisterType<AutofacComponent11>().As<IAutofacComponent>();
var autofacContainer = builder.Build();
var autofacComponent = autofacContainer.Resolve<IAutofacComponent>();
Assert.That(autofacComponent, Is.Not.Null);
Assert.That(autofacComponent.GetType(), Is.EqualTo(typeof(AutofacComponent11)));
Assert.That(autofacComponent.ImportedMefComponent.GetType(), Is.EqualTo(typeof(MefComponent1)));
Assert.That(autofacComponent.MefComponent.GetType(), Is.EqualTo(typeof(MefComponent1)));
var autofacComponent11 = (AutofacComponent11)autofacComponent;
var mefComponent = autofacComponent11.MefComponentFactory();
Assert.That(mefComponent, Is.SameAs(autofacComponent.MefComponent));
}
示例12: MefResolvesServiceRegisteredInAutofacByTypeTest
public void MefResolvesServiceRegisteredInAutofacByTypeTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Register catalog and types
builder.RegisterCatalog(assemblyCatalog);
// Registration
builder.RegisterType<AutofacOnlyComponent1>().As<IAutofacOnlyComponent>().InstancePerLifetimeScope();
var autofacContainer = builder.Build();
var compositionContainer = autofacContainer.Resolve<CompositionContainer>();
var fromMef = compositionContainer.GetExportedValue<IAutofacOnlyComponent>();
var fromAutofac = autofacContainer.Resolve<IAutofacOnlyComponent>();
Assert.That(fromMef, Is.Not.Null);
Assert.That(fromMef.GetType(), Is.EqualTo(typeof (AutofacOnlyComponent1)));
Assert.That(fromAutofac, Is.Not.Null);
Assert.That(fromAutofac.GetType(), Is.EqualTo(typeof (AutofacOnlyComponent1)));
Assert.That(fromMef, Is.EqualTo(fromAutofac));
}
示例13: AutofacResolvesAutofacComponentRegisteredWithoutInterfaceTest
public void AutofacResolvesAutofacComponentRegisteredWithoutInterfaceTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Register catalog and types
builder.RegisterCatalog(assemblyCatalog);
// Registration
builder.Register((c, p) => new AutofacComponent2(c.ResolveNamed<IMefComponent>("component2")));
builder.Register((c, p) => new AutofacComponent3(c.ResolveNamed<IMefComponent>("component2")));
var container = builder.Build();
var component2 = container.Resolve<AutofacComponent2>();
Assert.That(component2, Is.Not.Null);
Assert.That(component2.ImportedMefComponent, Is.Not.Null);
Assert.That(component2.ImportedMefComponent.GetType(), Is.EqualTo(typeof (MefComponent2)));
Assert.That(component2.MefComponent.GetType(), Is.EqualTo(typeof (MefComponent2)));
}
示例14: AutofacContainerCanBeResolvedByMefTest
public void AutofacContainerCanBeResolvedByMefTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Register catalog and types
builder.RegisterCatalog(assemblyCatalog);
// Test
var container = builder.Build();
var compositionContainer1 = container.Resolve<CompositionContainer>();
var compositionContainer2 = container.Resolve<CompositionContainer>();
Assert.That(compositionContainer1, Is.Not.Null);
Assert.That(compositionContainer2, Is.Not.Null);
Assert.That(compositionContainer1, Is.SameAs(compositionContainer2));
var autofacContainerFromMef1 = compositionContainer1.GetExportedValue<ILifetimeScope>();
var autofacContainerFromMef2 = compositionContainer1.GetExportedValue<ILifetimeScope>();
Assert.That(autofacContainerFromMef1, Is.Not.Null);
Assert.That(autofacContainerFromMef2, Is.Not.Null);
Assert.AreSame(autofacContainerFromMef1, autofacContainerFromMef2);
}
示例15: AutofacCircularDependencyIsDetectedTest
public void AutofacCircularDependencyIsDetectedTest()
{
// Setup
var builder = new ContainerBuilder();
builder.EnableCompositionIntegration();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
// Register catalog and types
builder.RegisterCatalog(assemblyCatalog);
builder.RegisterType<AutofacOnlyComponent1>();
// Test
var container = builder.Build();
var autofacOnlyComponent1 = container.Resolve<AutofacOnlyComponent1>();
Assert.That(autofacOnlyComponent1, Is.Not.Null);
}