本文整理汇总了C#中ContainerConfiguration类的典型用法代码示例。如果您正苦于以下问题:C# ContainerConfiguration类的具体用法?C# ContainerConfiguration怎么用?C# ContainerConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContainerConfiguration类属于命名空间,在下文中一共展示了ContainerConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
/// <summary>
/// 遅延初期化処理。
/// </summary>
/// <param name="token"></param>
private void Init(CancellationToken token, TaskScheduler uiSyncContext, Assembly callerAssembly)
{
logger.Trace("Init Start");
try
{
// MEFの構成
var qAssm = new[] {
this.GetType().Assembly,
Assembly.GetEntryAssembly(),
callerAssembly,
typeof(Pasta.Logging.PastaLogger).Assembly,
typeof(Pasta.Gleaners.Net.MailGleaner).Assembly,
}
.Where(a => a != null)
.Distinct();
var configuration = new ContainerConfiguration()
.WithAssemblies(qAssm)
;
var host = configuration.CreateContainer();
token.Register(() => host.Dispose());
// appの取得と構成
var app = host.GetExport<AppCore>();
app.Init(token,uiSyncContext);
Application = app;
logger.Trace("Init End");
}
catch (Exception ex)
{
logger.Error(ex);
}
}
示例2: Basic
public void Basic()
{
var types = new[] { typeof(Singleton) }.AsApplicationParts();
var container = new ContainerConfiguration().WithParts( types.AsEnumerable() ).WithProvider( SingletonExportDescriptorProvider.Default ).CreateContainer();
var export = container.GetExport<Singleton>();
Assert.Same( Singleton.Default, export );
}
示例3: Implementation
public void Implementation()
{
var types = new[] { typeof(Implemented) }.AsApplicationParts();
var container = new ContainerConfiguration().WithParts( types.AsEnumerable() ).WithProvider( SingletonExportDescriptorProvider.Default ).CreateContainer();
Assert.Same( Implemented.Default, container.GetExport<ISingleton>() );
Assert.Same( Implemented.Default, container.GetExport<Implemented>() );
}
示例4: ConfigureContainer
public static void ConfigureContainer()
{
var containerConventions = new ConventionBuilder();
containerConventions.ForType<DbProductRepository>()
.ExportInterfaces()
.SelectConstructorWithMostParameters()
.InstancePerHttpRequest();
containerConventions.ForType<DbLogger>()
.ExportInterfaces()
.SelectConstructorWithMostParameters()
.InstancePerHttpRequest();
containerConventions.ForType<ProductDbContext>()
.Export()
.InstancePerHttpRequest();
containerConventions.ForTypesDerivedFrom<Controller>()
.Export<IController>()
.Export()
.SelectConstructorWithMostParameters();
var containerConfig = new ContainerConfiguration();
containerConfig.WithAssembly(Assembly.GetExecutingAssembly(), containerConventions);
containerConfig.CreateContainer().UseWithMvc();
}
示例5: StandardExportInterfacesShouldWork
public void StandardExportInterfacesShouldWork()
{
// Export all interfaces except IDisposable, Export contracts on types without interfaces. except for disposable types
var builder = new ConventionBuilder();
builder.ForTypesMatching((t) => true).ExportInterfaces();
builder.ForTypesMatching((t) => t.GetTypeInfo().ImplementedInterfaces.Where((iface) => iface != typeof(System.IDisposable)).Count() == 0).Export();
var container = new ContainerConfiguration()
.WithPart<Standard>(builder)
.WithPart<Dippy>(builder)
.WithPart<Derived>(builder)
.WithPart<BareClass>(builder)
.CreateContainer();
var importer = new Importer();
container.SatisfyImports(importer);
Assert.NotNull(importer.First);
Assert.True(importer.First.Count() == 3);
Assert.NotNull(importer.Second);
Assert.True(importer.Second.Count() == 3);
Assert.NotNull(importer.Third);
Assert.True(importer.Third.Count() == 3);
Assert.NotNull(importer.Fourth);
Assert.True(importer.Fourth.Count() == 3);
Assert.NotNull(importer.Fifth);
Assert.True(importer.Fifth.Count() == 3);
Assert.Null(importer.Base);
Assert.Null(importer.Derived);
Assert.Null(importer.Dippy);
Assert.Null(importer.Standard);
Assert.Null(importer.Disposable);
Assert.NotNull(importer.BareClass);
}
示例6: CompleteInitialization
public static void CompleteInitialization()
{
Assembly[] partsAssemblies;
lock (_initLock)
{
if (_isInitialized)
return;
_isInitialized = true;
partsAssemblies = _partAssemblies.Union(FindWebApplicationAssemblies()).ToArray();
}
var conventions = new ConventionBuilder()
.WithMvcConventions()
.WithEagerConstructionSupport();
conventions.ForTypesUnderNamespace("Parts").Export().ExportInterfaces();
var container = new ContainerConfiguration()
.WithDefaultConventions(conventions)
.WithAssemblies(partsAssemblies)
.WithApplicationSettings()
.CreateContainer();
MvcCompositionProvider.Initialize(container);
CompositionFilterProvider.Install(FilterProviders.Providers);
ImportCapableFilterAttributeFilterProvider.Install(FilterProviders.Providers);
container.ConstructEagerParts();
}
示例7: QueryProviders
public void QueryProviders(IEnumerable<Assembly> assemblies)
{
var configuration = new ContainerConfiguration().WithAssemblies(assemblies);
using (var container = configuration.CreateContainer())
{
container.SatisfyImports(this);
}
}
示例8: InitializeContainer
public void InitializeContainer(params Type[] parts)
{
var configuration = new ContainerConfiguration().WithParts(parts);
using (CompositionHost host = configuration.CreateContainer())
{
host.SatisfyImports(_calcImport);
}
}
示例9: Many
public void Many()
{
var types = new[] { typeof(Implemented), typeof(AnotherImplemented) }.AsApplicationParts();
var container = new ContainerConfiguration().WithParts( types.AsEnumerable() ).WithProvider( SingletonExportDescriptorProvider.Default ).CreateContainer();
var exports = container.GetExports<ISingleton>().Fixed();
Assert.Contains( Implemented.Default, exports );
Assert.Contains( AnotherImplemented.Default, exports );
}
示例10: CreateContainer
private CompositionContext CreateContainer(params Type[] types)
{
var configuration = new ContainerConfiguration()
.WithParts(types)
.WithProvider(new DictionaryExportDescriptorProvider());
return configuration.CreateContainer();
}
示例11: BuildLocator
private static IServiceLocator BuildLocator()
{
var configuration = new ContainerConfiguration();
configuration.RegisterComponents(typeof(IFoo).Assembly);
var container = configuration.CreateContainer();
return new MefServiceLocator(container);
}
示例12: GetContainer
private CompositionHost GetContainer(IEnumerable<Assembly> assemblies)
{
var configuration = new ContainerConfiguration();
foreach (var assembly in assemblies)
{
configuration.WithAssembly(assembly);
}
return configuration.CreateContainer();
}
示例13: MainPage
public MainPage()
{
var containerConfiguration = new ContainerConfiguration().WithAssembly(typeof(App).GetTypeInfo().Assembly);
CompositionHost host = containerConfiguration.CreateContainer();
host.SatisfyImports(this);
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
示例14: ProvidersCanDetectAbsenceOfAContractItSupports
public void ProvidersCanDetectAbsenceOfAContractItSupports()
{
var container = new ContainerConfiguration()
.WithProvider(new DefaultObjectExportDescriptorProvider())
.CreateContainer();
var o = container.GetExport<object>();
Assert.Equal(DefaultObjectExportDescriptorProvider.DefaultObject, o);
}
示例15: AConcreteTypeWithDictionaryConstructorIsAMetadataView
public void AConcreteTypeWithDictionaryConstructorIsAMetadataView()
{
var cc = new ContainerConfiguration()
.WithPart<HasNameA>()
.CreateContainer();
var hn = cc.GetExport<Lazy<HasNameA, DictionaryName>>();
Assert.Equal("A", hn.Metadata.RetrievedName);
}