本文整理汇总了C#中ContainerConfiguration.WithAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerConfiguration.WithAssembly方法的具体用法?C# ContainerConfiguration.WithAssembly怎么用?C# ContainerConfiguration.WithAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerConfiguration
的用法示例。
在下文中一共展示了ContainerConfiguration.WithAssembly方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: GetContainer
private CompositionHost GetContainer(IEnumerable<Assembly> assemblies)
{
var configuration = new ContainerConfiguration();
foreach (var assembly in assemblies)
{
configuration.WithAssembly(assembly);
}
return configuration.CreateContainer();
}
示例3: ConfigureMef
public static CompositionHost ConfigureMef(IServiceProvider serviceProvider,
OmniSharpOptions options,
IEnumerable<Assembly> assemblies,
Func<ContainerConfiguration, ContainerConfiguration> configure = null)
{
var config = new ContainerConfiguration();
assemblies = assemblies
.Concat(new[] { typeof(OmnisharpWorkspace).GetTypeInfo().Assembly, typeof(IRequest).GetTypeInfo().Assembly })
.Distinct();
foreach (var assembly in assemblies)
{
config = config.WithAssembly(assembly);
}
var memoryCache = serviceProvider.GetService<IMemoryCache>();
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
var env = serviceProvider.GetService<IOmnisharpEnvironment>();
var writer = serviceProvider.GetService<ISharedTextWriter>();
var applicationLifetime = serviceProvider.GetService<IApplicationLifetime>();
var loader = serviceProvider.GetService<IOmnisharpAssemblyLoader>();
config = config
.WithProvider(MefValueProvider.From(serviceProvider))
.WithProvider(MefValueProvider.From<IFileSystemWatcher>(new ManualFileSystemWatcher()))
.WithProvider(MefValueProvider.From(memoryCache))
.WithProvider(MefValueProvider.From(loggerFactory))
.WithProvider(MefValueProvider.From(env))
.WithProvider(MefValueProvider.From(writer))
.WithProvider(MefValueProvider.From(applicationLifetime))
.WithProvider(MefValueProvider.From(options))
.WithProvider(MefValueProvider.From(options.FormattingOptions))
.WithProvider(MefValueProvider.From(loader))
.WithProvider(MefValueProvider.From(new MetadataHelper(loader))); // other way to do singleton and autowire?
if (env.TransportType == TransportType.Stdio)
{
config = config
.WithProvider(MefValueProvider.From<IEventEmitter>(new StdioEventEmitter(writer)));
}
else
{
config = config
.WithProvider(MefValueProvider.From<IEventEmitter>(new NullEventEmitter()));
}
if (configure != null)
config = configure(config);
var container = config.CreateContainer();
return container;
}
示例4: 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();
}
示例5: Init
public void Init()
{
var a1 = System.Reflection.Assembly.LoadFile(Environment.CurrentDirectory + "/CozyQuick.Plugin.Timer.dll");
var a2 = System.Reflection.Assembly.LoadFile(Environment.CurrentDirectory + "/CozyQuick.Plugin.Msgbox.dll");
var configuration1 = new ContainerConfiguration();
configuration1.WithAssembly(a1);
var c1 = configuration1.CreateContainer();
_pub = c1.GetExport<IEventPublish>();
var configuration2 = new ContainerConfiguration();
configuration2.WithAssembly(a2);
var c2 = configuration2.CreateContainer();
_sub = c2.GetExport<IEventSubscribe>();
_pub.Init(this);
_pub.ShowPublishConfigurePanel();
}
示例6: GetContainer
private CompositionHost GetContainer(IEnumerable<Assembly> assemblies)
{
var configuration = new ContainerConfiguration();
foreach (var assembly in assemblies)
{
configuration.WithAssembly(assembly);
}
try
{
return configuration.CreateContainer();
}
catch (ReflectionTypeLoadException ex)
{
Logger.LogError(
$"Error when get composition container: {ex.Message}, loader exceptions: {(ex.LoaderExceptions != null ? string.Join(", ", ex.LoaderExceptions.Select(e => e.Message)) : "none")}");
throw;
}
}
示例7: Main
private static void Main(string[] args)
{
var pluginDir = args.Any() ? args[0] : @"..\..\..\Plugins";
// Add ourself to the ContainerConfiguration because we might have
// embedded components.
var partConfig = new ContainerConfiguration()
.WithAssembly(Assembly.GetExecutingAssembly());
// Now add in assemblies in the plugins directory.
var dInfo = new DirectoryInfo(pluginDir);
var files = dInfo.GetFiles("*.dll");
foreach (var file in files)
partConfig.WithAssembly(Assembly.LoadFile(file.FullName));
object description;
var compositionHost = partConfig.CreateContainer();
var algorithms = compositionHost.GetExports
<ExportFactory<IFizzBuzzAlgorithm, IDictionary<string, object>>>();
var writers = compositionHost.GetExports
<ExportFactory<IFizzBuzzWriter, IDictionary<string, object>>>();
Console.WriteLine();
Console.WriteLine("Algorithm plugins:");
if (algorithms != null)
foreach (var a in algorithms)
{
a.Metadata.TryGetValue("Description", out description);
Console.WriteLine(@" {0}", description);
}
Console.WriteLine();
Console.WriteLine("Writer plugins:");
if (writers != null)
foreach (var w in writers)
{
w.Metadata.TryGetValue("Description", out description);
Console.WriteLine(@" {0}", description);
}
Utility.Pause("");
}
示例8: Create
public static DefaultRuleProvider Create(Settings settings)
{
var result = new DefaultRuleProvider();
// Inject rules using MEF
var config = new ContainerConfiguration();
var assemblyPath = Assembly.LoadFrom(ConfigManager.Current.RuleLibraryPath);
config.WithAssembly(assemblyPath);
using (var container = config.CreateContainer())
{
container.SatisfyImports(result);
}
// Set rules settings
foreach (var rule in result.Rules)
{
rule.Settings = settings;
}
return result;
}
示例9: GetContainer
private CompositionHost GetContainer()
{
var configuration = new ContainerConfiguration();
configuration.WithAssembly(typeof(CommandController).Assembly);
return configuration.CreateContainer();
}
示例10: ConfigureContainer
protected virtual void ConfigureContainer(ContainerConfiguration config)
{
config.WithAssembly(typeof(Application).GetTypeInfo().Assembly);
config.WithAssembly(GetType().GetTypeInfo().Assembly);
EachPlugin(p => p.ConfigureContainer(config));
}