当前位置: 首页>>代码示例>>C#>>正文


C# ContainerConfiguration.WithAssembly方法代码示例

本文整理汇总了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();
        }
开发者ID:Hem,项目名称:MvcMefProvider,代码行数:28,代码来源:MefContainer.cs

示例2: GetContainer

 private CompositionHost GetContainer(IEnumerable<Assembly> assemblies)
 {
     var configuration = new ContainerConfiguration();
     foreach (var assembly in assemblies)
     {
         configuration.WithAssembly(assembly);
     }
     return configuration.CreateContainer();
 }
开发者ID:yonglehou,项目名称:docfx,代码行数:9,代码来源:DocumentBuilder.cs

示例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;
        }
开发者ID:RLittlesII,项目名称:omnisharp-roslyn,代码行数:52,代码来源:Startup.cs

示例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();
        }
开发者ID:yasu-s,项目名称:MEF-Sample,代码行数:17,代码来源:Program.cs

示例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();
        } 
开发者ID:xxy1991,项目名称:cozy,代码行数:16,代码来源:EngineImpl.cs

示例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;
     }
 }
开发者ID:yodamaster,项目名称:docfx,代码行数:18,代码来源:DocumentBuilder.cs

示例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("");
        }
开发者ID:Tulsagrammer,项目名称:FizzBuzz,代码行数:40,代码来源:Program.cs

示例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;
        }
开发者ID:ngkolev,项目名称:Skeptic.NET,代码行数:22,代码来源:DefaultRuleProvider.cs

示例9: GetContainer

 private CompositionHost GetContainer()
 {
     var configuration = new ContainerConfiguration();
     configuration.WithAssembly(typeof(CommandController).Assembly);
     return configuration.CreateContainer();
 }
开发者ID:dotnet,项目名称:docfx,代码行数:6,代码来源:CommandController.cs

示例10: ConfigureContainer

 protected virtual void ConfigureContainer(ContainerConfiguration config)
 {
     config.WithAssembly(typeof(Application).GetTypeInfo().Assembly);
     config.WithAssembly(GetType().GetTypeInfo().Assembly);
     EachPlugin(p => p.ConfigureContainer(config));
 }
开发者ID:anurse,项目名称:AppRT,代码行数:6,代码来源:Application.cs


注:本文中的ContainerConfiguration.WithAssembly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。