本文整理汇总了C#中ContainerConfiguration.CreateContainer方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerConfiguration.CreateContainer方法的具体用法?C# ContainerConfiguration.CreateContainer怎么用?C# ContainerConfiguration.CreateContainer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerConfiguration
的用法示例。
在下文中一共展示了ContainerConfiguration.CreateContainer方法的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: 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();
}
示例3: QueryProviders
public void QueryProviders(IEnumerable<Assembly> assemblies)
{
var configuration = new ContainerConfiguration().WithAssemblies(assemblies);
using (var container = configuration.CreateContainer())
{
container.SatisfyImports(this);
}
}
示例4: InitializeContainer
public void InitializeContainer(params Type[] parts)
{
var configuration = new ContainerConfiguration().WithParts(parts);
using (CompositionHost host = configuration.CreateContainer())
{
host.SatisfyImports(_calcImport);
}
}
示例5: CreateContainer
private CompositionContext CreateContainer(params Type[] types)
{
var configuration = new ContainerConfiguration()
.WithParts(types)
.WithProvider(new DictionaryExportDescriptorProvider());
return configuration.CreateContainer();
}
示例6: 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;
}
示例7: GetContainer
private CompositionHost GetContainer(IEnumerable<Assembly> assemblies)
{
var configuration = new ContainerConfiguration();
foreach (var assembly in assemblies)
{
configuration.WithAssembly(assembly);
}
return configuration.CreateContainer();
}
示例8: BuildLocator
private static IServiceLocator BuildLocator()
{
var configuration = new ContainerConfiguration();
configuration.RegisterComponents(typeof(IFoo).Assembly);
var container = configuration.CreateContainer();
return new MefServiceLocator(container);
}
示例9: Bootstrapper
public void Bootstrapper()
{
var configuration = new ContainerConfiguration()
.WithPart<Calculator>();
using (CompositionHost host = configuration.CreateContainer())
{
// Calculator = host.GetExport<ICalculator>();
host.SatisfyImports(this);
}
}
示例10: Compose
protected void Compose()
{
// Create the container
var config = new ContainerConfiguration();
ConfigureContainer(config);
_container = config.CreateContainer();
// Compose the application
_container.SatisfyImports(this);
}
示例11: OnInitialize
protected override void OnInitialize()
{
base.OnInitialize();
Context = UnitTestSynchronizationContext.Create();
var configuration = new ContainerConfiguration()
.WithAssembly(typeof(ShellViewModel).GetTypeInfo().Assembly)
.WithAssembly(typeof(ApplicationsTest).GetTypeInfo().Assembly);
Container = configuration.CreateContainer();
}
示例12: Main
private static void Main(string[] args) {
var configuration = new ContainerConfiguration()
.WithAssembly(typeof(Channel).Assembly)
.WithPart(typeof(DesktopCryptoProvider))
.WithPart(typeof(DesktopChannel))
.WithPart(typeof(Program));
var container = configuration.CreateContainer();
var program = container.GetExport<Program>();
program.DoAsync().GetAwaiter().GetResult();
}
示例13: Prepare
public override void Prepare()
{
var config = new ContainerConfiguration();
RegisterBasic(config);
RegisterPropertyInjection(config);
RegisterMultiple(config);
RegisterOpenGeneric(config);
this.container = config.CreateContainer();
}
示例14: ShouldForwardResolveToInnerContainerWhenKeyIsUsed
public void ShouldForwardResolveToInnerContainerWhenKeyIsUsed()
{
object myInstance = new object();
ContainerConfiguration config = new ContainerConfiguration();
config.WithExport<object>(myInstance, "key");
MefServiceLocatorAdapter.CompositionContainer = config.CreateContainer();
IServiceLocator containerAdapter = new MefServiceLocatorAdapter();
Assert.AreSame(myInstance, containerAdapter.GetInstance(typeof(object), "key"));
}
示例15: GetContainer
/// <summary>
/// <see cref="CompositionContext"/>生成
/// </summary>
/// <returns></returns>
private static CompositionContext GetContainer()
{
var config = new ContainerConfiguration();
config.WithAssembly(typeof(Program).Assembly);
//var builder = new ConventionBuilder();
//builder.ForType<Logger>().Export<ILogger>();
//config.WithAssembly(typeof(Program).Assembly, builder);
config.WithProvider(new LogExportDescriptorProvider());
return config.CreateContainer();
}