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


C# ContainerBuilder.RegisterComposablePartCatalog方法代码示例

本文整理汇总了C#中Autofac.ContainerBuilder.RegisterComposablePartCatalog方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterComposablePartCatalog方法的具体用法?C# ContainerBuilder.RegisterComposablePartCatalog怎么用?C# ContainerBuilder.RegisterComposablePartCatalog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Autofac.ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder.RegisterComposablePartCatalog方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

 public void Init()
 {
     var builder = new ContainerBuilder();
     builder.RegisterComposablePartCatalog(new AssemblyCatalog(Assembly.GetAssembly(typeof(TestEntity))));
     builder.RegisterComposablePartCatalog(new AssemblyCatalog(Assembly.GetAssembly(typeof(ITestEntityProxy))));
     builder.RegisterType<EntityDomain>().As<IEntityDomain>();
     builder.RegisterType<EntityRepository>().As<IEntityRepository>();
     builder.RegisterType<MessageFactory>().As<IMessageFactory>();
     builder.RegisterType<RakPeerInterface>().As<INetPeer>();
     builder.RegisterType<EntityClusterNode>().As<IEntityClusterNode>();
     builder.RegisterType<NullPersistanceProvider>().As<IPersistanceProvider>();
     container = builder.Build();
 }
开发者ID:tlotter,项目名称:MassiveOnlineUniversalServerEngine,代码行数:13,代码来源:EntityUsageTests.cs

示例2: LoadPlugins

 private void LoadPlugins()
 {
     var builder = new ContainerBuilder();
     var aggregateCatalog = new AggregateCatalog();
     aggregateCatalog.Catalogs.Add(new DirectoryCatalog("Plugins", "TestApp.*.dll"));
     builder.RegisterComposablePartCatalog(aggregateCatalog);
     _container = builder.Build();
 }
开发者ID:navtechradar,项目名称:Test,代码行数:8,代码来源:ServiceHostManager.cs

示例3: OnApplicationStarting

        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication,
            ApplicationContext applicationContext)
        {
            var viewPaths = new List<string>()
            {
                "~/Views/{0}.cshtml",
                "~/Views/{0}/{1}.cshtml",
                "~/Views/Shared/{0}.cshtml",
                "~/Views/Partials/{0}.cshtml",
                "~/Views/Region/{0}.cshtml",
                "~/Views/Widget/{0}.cshtml"
            };
            var catalog = new AggregateCatalog();

            var curentAssembly = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            catalog.Catalogs.Add(curentAssembly);
            var builder = new ContainerBuilder();
            builder.Register(c => UmbracoContext.Current).AsSelf();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);

            foreach (var path in Directory.EnumerateDirectories(AppDomain.CurrentDomain.BaseDirectory + "\\Plugins", "*Widget*", SearchOption.TopDirectoryOnly))
            {
                catalog.Catalogs.Add(new DirectoryCatalog(path));
                var pluginName = path.Split('\\');
                viewPaths.Add(String.Format("~/Plugins/{0}/Views/{1}.cshtml", pluginName[pluginName.Length - 1], "{0}"));
                var pluginAssembly = Assembly.Load(pluginName[pluginName.Length - 1]);
                builder.RegisterControllers(pluginAssembly);
                
                //ToDo: Add routes to view engine for none umbraco ones (below errors with No Tempalte
                //RouteTable.Routes.MapRoute(pluginName[pluginName.Length - 1], "{controller}/{action}", new
                //{
                //    controller = pluginName[pluginName.Length - 1],
                //    action = "RenderWidget",
                //    id = UrlParameter.Optional
                //});
            }

            ViewEngines.Engines.Add(new UmbracoToolboxViewEngine(viewPaths.ToArray()));
            builder.RegisterComposablePartCatalog(catalog);

           
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            var resolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;

            
        }
开发者ID:CodeChronicler,项目名称:UmbracoToolbox,代码行数:52,代码来源:ApplicationStartEventHandler.cs

示例4: Initialize

        public void Initialize()
        {
            var builder = new ContainerBuilder();
            var types = new[]
                {
                    typeof (ScriptHostFactory),
                    typeof (FileSystem),
                    typeof (PackageAssemblyResolver),
                    typeof (PackageContainer),
                    typeof (FilePreProcessor),
                    typeof (ScriptPackResolver),
                    typeof (NugetInstallationProvider),
                    typeof (PackageInstaller)
                };

            builder.RegisterTypes(types).AsImplementedInterfaces();

            if (_debug)
            {
                builder.RegisterType<DebugScriptExecutor>().As<IScriptExecutor>();
                builder.RegisterType<RoslynScriptDebuggerEngine>().As<IScriptEngine>();
            }
            else
            {
                builder.RegisterType<ScriptExecutor>().As<IScriptExecutor>();
                builder.RegisterType<RoslynScriptEngine>().As<IScriptEngine>();
            }

            builder.RegisterType<ScriptServiceRoot>().As<ScriptServiceRoot>();

            if (_shouldInitDrirectoryCatalog)
            {
                var scriptPath = Path.Combine(Environment.CurrentDirectory, "bin");
                if (Directory.Exists(scriptPath))
                {
                    var catalog = new DirectoryCatalog(scriptPath);
                    builder.RegisterComposablePartCatalog(catalog);
                }
            }
            _container = builder.Build();
            _scriptServiceRoot = _container.Resolve<ScriptServiceRoot>();
        }
开发者ID:jdecuyper,项目名称:scriptcs,代码行数:42,代码来源:CompositionRoot.cs

示例5: AppBootstrapper

        public AppBootstrapper()
        {
            Assembly currentAssembly = Assembly.GetExecutingAssembly();
            ContainerBuilder builder = new ContainerBuilder();
            AggregateCatalog catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(currentAssembly));
            builder.RegisterComposablePartCatalog(catalog);

            builder.RegisterAssemblyTypes(currentAssembly)
                .AsImplementedInterfaces();

            // ReactiveIRC.Client
            builder.RegisterType<Client>()
                .As<IClient>()
                .Exported(x => x.As<IClient>())
                .SingleInstance()
                ;

            // Veda.Storage
            builder.RegisterType<JsonStorage>()
                .As<IStorage>()
                .As<IOpenableStorage>()
                .Exported(x => x.As<IStorage>())
                .Exported(x => x.As<IOpenableStorage>())
                ;
            builder.Register((c, p) => new StorageManager(p.Named<String>("path"), p.Named<String>("extension"),
                p.Named<String>("globalFile")))
                .As<IPluginStorageManager>()
                .As<IStorageManager>()
                .Exported(x => x.As<IPluginStorageManager>())
                .Exported(x => x.As<IStorageManager>())
                .SingleInstance()
                ;

            // Veda.Plugin
            builder.RegisterType<PluginManager>()
                .As<IPluginManager>()
                .Exported(x => x.As<IPluginManager>())
                .SingleInstance()
                ;

            // Veda.Command
            builder.RegisterType<CommandParser>()
                .As<ICommandParser>()
                .Exported(x => x.As<ICommandParser>())
                .SingleInstance()
                ;
            builder.RegisterType<CommandManager>()
                .As<ICommandManager>()
                .Exported(x => x.As<ICommandManager>())
                .SingleInstance()
                ;

            // Veda.Authentication
            builder.RegisterType<AuthenticationManager>()
                .As<IAuthenticationManager>()
                .Exported(x => x.As<IAuthenticationManager>())
                .SingleInstance()
                ;
            builder.RegisterType<BotUser>()
                .As<IBotUser>()
                .Exported(x => x.As<IBotUser>())
                ;
            builder.RegisterType<BotGroup>()
                .As<IBotGroup>()
                .Exported(x => x.As<IBotGroup>())
                ;

            // Veda.Authentication
            builder.RegisterType<PermissionManager>()
                .As<IPluginPermissionManager>()
                .As<IPermissionManager>()
                .Exported(x => x.As<IPluginPermissionManager>())
                .Exported(x => x.As<IPermissionManager>())
                .SingleInstance()
                ;

            // Veda
            builder.RegisterType<Bot>()
                .As<IBot>()
                .Exported(x => x.As<IBot>())
                .SingleInstance()
                ;

            CompositionManager.ConfigureDependencies(builder, catalog);
        }
开发者ID:Gohla,项目名称:Veda,代码行数:87,代码来源:AppBootstrapper.cs

示例6: CreateContainer

        protected override IContainer CreateContainer()
        {
            var builder = new ContainerBuilder();
            _logger.Debug("Registering runtime services");

            builder.RegisterInstance<ILog>(_logger).Exported(x => x.As<ILog>());
            builder.RegisterType(_scriptEngineType).As<IScriptEngine>().SingleInstance();
            builder.RegisterType(_scriptExecutorType).As<IScriptExecutor>().SingleInstance();
            builder.RegisterInstance(_console).As<IConsole>();
            builder.RegisterType<ScriptServices>().SingleInstance();

            RegisterOverrideOrDefault<IFileSystem>(builder, b => b.RegisterType<FileSystem>().As<IFileSystem>().SingleInstance());
            RegisterOverrideOrDefault<IAssemblyUtility>(builder, b => b.RegisterType<AssemblyUtility>().As<IAssemblyUtility>().SingleInstance());
            RegisterOverrideOrDefault<IPackageContainer>(builder, b => b.RegisterType<PackageContainer>().As<IPackageContainer>().SingleInstance());
            RegisterOverrideOrDefault<IPackageAssemblyResolver>(builder, b => b.RegisterType<PackageAssemblyResolver>().As<IPackageAssemblyResolver>().SingleInstance());
            RegisterOverrideOrDefault<IAssemblyResolver>(builder, b => b.RegisterType<AssemblyResolver>().As<IAssemblyResolver>().SingleInstance());
            RegisterOverrideOrDefault<IScriptHostFactory>(builder, b => b.RegisterType<ScriptHostFactory>().As<IScriptHostFactory>().SingleInstance());
            RegisterOverrideOrDefault<IFilePreProcessor>(builder, b => b.RegisterType<FilePreProcessor>().As<IFilePreProcessor>().SingleInstance());
            RegisterOverrideOrDefault<IScriptPackResolver>(builder, b => b.RegisterType<ScriptPackResolver>().As<IScriptPackResolver>().SingleInstance());
            RegisterOverrideOrDefault<IInstallationProvider>(builder, b => b.RegisterType<NugetInstallationProvider>().As<IInstallationProvider>().SingleInstance());
            RegisterOverrideOrDefault<IPackageInstaller>(builder, b => b.RegisterType<PackageInstaller>().As<IPackageInstaller>().SingleInstance());
            RegisterOverrideOrDefault<ScriptServices>(builder, b => b.RegisterType<ScriptServices>().SingleInstance());

            var assemblyResolver = _initializationServices.GetAssemblyResolver();

            if (_initDirectoryCatalog)
            {
                var currentDirectory = Environment.CurrentDirectory;
                var assemblies = assemblyResolver.GetAssemblyPaths(currentDirectory);

                var aggregateCatalog = new AggregateCatalog();

                assemblies.Select(x => new AssemblyCatalog(x)).ToList()
                    .ForEach(catalog => aggregateCatalog.Catalogs.Add(catalog));

                builder.RegisterComposablePartCatalog(aggregateCatalog);
            }

            return builder.Build();
        }
开发者ID:jonparker,项目名称:scriptcs,代码行数:40,代码来源:RuntimeServices.cs

示例7: CreateContainer


//.........这里部分代码省略.........
            RegisterLineProcessors(builder);
            RegisterReplCommands(builder);

            RegisterOverrideOrDefault<IFileSystem>(
                builder, b => b.RegisterType<FileSystem>().As<IFileSystem>().SingleInstance());

            RegisterOverrideOrDefault<IAssemblyUtility>(
                builder, b => b.RegisterType<AssemblyUtility>().As<IAssemblyUtility>().SingleInstance());

            RegisterOverrideOrDefault<IPackageContainer>(
                builder, b => b.RegisterType<PackageContainer>().As<IPackageContainer>().SingleInstance());

            RegisterOverrideOrDefault<IPackageAssemblyResolver>(
                builder, b => b.RegisterType<PackageAssemblyResolver>().As<IPackageAssemblyResolver>().SingleInstance());

            RegisterOverrideOrDefault<IAssemblyResolver>(
                builder, b => b.RegisterType<AssemblyResolver>().As<IAssemblyResolver>().SingleInstance());

            RegisterOverrideOrDefault<IScriptHostFactory>(
                builder, b => b.RegisterType<ScriptHostFactory>().As<IScriptHostFactory>().SingleInstance());

            RegisterOverrideOrDefault<IFilePreProcessor>(
                builder, b => b.RegisterType<FilePreProcessor>().As<IFilePreProcessor>().SingleInstance());

            RegisterOverrideOrDefault<IScriptPackResolver>(
                builder, b => b.RegisterType<ScriptPackResolver>().As<IScriptPackResolver>().SingleInstance());

            RegisterOverrideOrDefault<IInstallationProvider>(
                builder, b => b.RegisterType<NugetInstallationProvider>().As<IInstallationProvider>().SingleInstance());

            RegisterOverrideOrDefault<IPackageInstaller>(
                builder, b => b.RegisterType<PackageInstaller>().As<IPackageInstaller>().SingleInstance());

            RegisterOverrideOrDefault<ScriptServices>(
                builder, b => b.RegisterType<ScriptServices>().SingleInstance());

            RegisterOverrideOrDefault<IObjectSerializer>(
                builder, b => b.RegisterType<ObjectSerializer>().As<IObjectSerializer>().SingleInstance());

            RegisterOverrideOrDefault<IConsole>(
                builder, b => b.RegisterInstance(_console));

            RegisterOverrideOrDefault<IFileSystemMigrator>(
                builder, b => b.RegisterType<FileSystemMigrator>().As<IFileSystemMigrator>().SingleInstance());

            RegisterOverrideOrDefault<IScriptLibraryComposer>(
                builder, b => b.RegisterType<ScriptLibraryComposer>().As<IScriptLibraryComposer>().SingleInstance());

            RegisterOverrideOrDefault<IVisualStudioSolutionWriter>(
                builder, b => b.RegisterType<VisualStudioSolutionWriter>().As<IVisualStudioSolutionWriter>().SingleInstance());

            if (_initDirectoryCatalog)
            {
                var fileSystem = _initializationServices.GetFileSystem();

                var assemblies = _initializationServices.GetAssemblyResolver()
                    .GetAssemblyPaths(fileSystem.GetWorkingDirectory(_scriptName))
                    .Where(assembly => ShouldLoadAssembly(fileSystem, _initializationServices.GetAssemblyUtility(), assembly));

                var aggregateCatalog = new AggregateCatalog();
                var assemblyLoadFailures = false;

                foreach (var assemblyPath in assemblies)
                {
                    try
                    {
                        var catalog = new AssemblyCatalog(assemblyPath);
                        // force the parts to be queried to catch any errors that would otherwise show up later
                        catalog.Parts.ToList();
                        aggregateCatalog.Catalogs.Add(catalog);
                    }
                    catch (ReflectionTypeLoadException typeLoadEx)
                    {
                        assemblyLoadFailures = true;
                        if (typeLoadEx.LoaderExceptions != null && typeLoadEx.LoaderExceptions.Any())
                        {
                            foreach (var ex in typeLoadEx.LoaderExceptions.GroupBy(x => x.Message))
                            {
                                _log.DebugFormat(
                                    "Failure loading assembly: {0}. Exception: {1}", assemblyPath, ex.First().Message);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        assemblyLoadFailures = true;
                        _log.DebugFormat("Failure loading assembly: {0}. Exception: {1}", assemblyPath, ex.Message);
                    }
                }
                if (assemblyLoadFailures)
                {
                    _log.Warn(string.IsNullOrEmpty(_scriptName)
                        ? "Some assemblies failed to load. Launch with '-repl -loglevel debug' to see the details"
                        : "Some assemblies failed to load. Launch with '-loglevel debug' to see the details");
                }
                builder.RegisterComposablePartCatalog(aggregateCatalog);
            }

            return builder.Build();
        }
开发者ID:scriptcs,项目名称:scriptcs,代码行数:101,代码来源:RuntimeServices.cs

示例8: CreateContainer

        protected override IContainer CreateContainer()
        {
            var builder = new ContainerBuilder();
            this.Logger.Debug("Registering runtime services");

            builder.RegisterInstance<ILog>(this.Logger).Exported(x => x.As<ILog>());
            builder.RegisterType(_scriptEngineType).As<IScriptEngine>().SingleInstance();
            builder.RegisterType(_scriptExecutorType).As<IScriptExecutor>().SingleInstance();
            builder.RegisterType<ScriptServices>().SingleInstance();

            RegisterLineProcessors(builder);

            RegisterOverrideOrDefault<IFileSystem>(builder, b => b.RegisterType<FileSystem>().As<IFileSystem>().SingleInstance());
            RegisterOverrideOrDefault<IAssemblyUtility>(builder, b => b.RegisterType<AssemblyUtility>().As<IAssemblyUtility>().SingleInstance());
            RegisterOverrideOrDefault<IPackageContainer>(builder, b => b.RegisterType<PackageContainer>().As<IPackageContainer>().SingleInstance());
            RegisterOverrideOrDefault<IPackageAssemblyResolver>(builder, b => b.RegisterType<PackageAssemblyResolver>().As<IPackageAssemblyResolver>().SingleInstance());
            RegisterOverrideOrDefault<IAssemblyResolver>(builder, b => b.RegisterType<AssemblyResolver>().As<IAssemblyResolver>().SingleInstance());
            RegisterOverrideOrDefault<IScriptHostFactory>(builder, b => b.RegisterType<ScriptHostFactory>().As<IScriptHostFactory>().SingleInstance());
            RegisterOverrideOrDefault<IFilePreProcessor>(builder, b => b.RegisterType<FilePreProcessor>().As<IFilePreProcessor>().SingleInstance());
            RegisterOverrideOrDefault<IScriptPackResolver>(builder, b => b.RegisterType<ScriptPackResolver>().As<IScriptPackResolver>().SingleInstance());
            RegisterOverrideOrDefault<IInstallationProvider>(builder, b => b.RegisterType<NugetInstallationProvider>().As<IInstallationProvider>().SingleInstance());
            RegisterOverrideOrDefault<IPackageInstaller>(builder, b => b.RegisterType<PackageInstaller>().As<IPackageInstaller>().SingleInstance());
            RegisterOverrideOrDefault<ScriptServices>(builder, b => b.RegisterType<ScriptServices>().SingleInstance());
            RegisterOverrideOrDefault<IObjectSerializer>(builder, b => b.RegisterType<ObjectSerializer>().As<IObjectSerializer>().SingleInstance());
            RegisterOverrideOrDefault<IConsole>(builder, b => b.RegisterInstance(_console));

            var assemblyResolver = _initializationServices.GetAssemblyResolver();

            if (_initDirectoryCatalog)
            {
                var fileSystem = _initializationServices.GetFileSystem();
                var currentDirectory = fileSystem.GetWorkingDirectory(_scriptName);
                var assemblies = assemblyResolver.GetAssemblyPaths(currentDirectory);

                var aggregateCatalog = new AggregateCatalog();
                bool assemblyLoadFailures = false;

                foreach (var assembly in assemblies)
                {
                    try
                    {
                        var catalog = new AssemblyCatalog(assembly);
                        catalog.Parts.ToList(); //force the Parts to be read
                        aggregateCatalog.Catalogs.Add(catalog);
                    }
                    catch(Exception ex)
                    {
                        assemblyLoadFailures = true;
                        Logger.DebugFormat("Failure loading assembly: {0}. Exception: {1}", assembly, ex.Message);
                    }
                }
                if (assemblyLoadFailures)
                {
                    if (_scriptName == null || _scriptName.Length == 0)
                        Logger.Warn("Some assemblies failed to load. Launch with '-repl -loglevel debug' to see the details");
                    else
                        Logger.Warn("Some assemblies failed to load. Launch with '-loglevel debug' to see the details");
                }
                builder.RegisterComposablePartCatalog(aggregateCatalog);
            }

            return builder.Build();
        }
开发者ID:Jaydeep7,项目名称:scriptcs,代码行数:63,代码来源:RuntimeServices.cs

示例9: App

        static App()
        {
            var catalog = new AssemblyCatalog(typeof(App).Assembly);
            var builder = new ContainerBuilder();

            builder.RegisterComposablePartCatalog(catalog);

            builder
                .Register(_ => App.Current)
                .As<Application>()
                .ExternallyOwned()
                .InstancePerLifetimeScope();

            builder
                .Register(b => new MainViewModel())
                .OnActivating(e =>
                {
                    e.Instance.StartCommand = e.Context.Resolve<StartCommand>();
                    e.Instance.StopCommand = e.Context.Resolve<StopCommand>();
                    e.Instance.SearchCommand = e.Context.Resolve<SearchCommand>();
                })
                .AsSelf()
                .InstancePerLifetimeScope();

            builder
                .Register(b => YouTrackManager.GetConnection("youtrack.neveling.net", "testuser", "testuser"))
                .As<IConnection>()
                .InstancePerLifetimeScope();

            builder
                .Register(b=>new IssueManagement(b.Resolve<IConnection>()))
                .AsSelf()
                .InstancePerLifetimeScope();

            builder
                .RegisterType(typeof (YouTrackRepository))
                .As(typeof(IRepository<string, IRepositoryPayload>))
                .InstancePerLifetimeScope();

            builder
                .RegisterType<YouTrackPayload>()
                .OnActivated(e=>e.Instance.Repository = e.Context.Resolve<IRepository<string, IRepositoryPayload>>())
                .As<IRepositoryPayload>()
                .InstancePerDependency();

            builder
                .RegisterType<StartCommand>()
                .OnActivated(e =>
                {
                    e.Instance.MainViewModel = e.Context.Resolve<MainViewModel>();
                    e.Instance.StartEventFactory =
                        () => new TrakkrEventViewModel
                        {
                            Type = EventType.Start,
                            Timestamp = DateTime.Now,
                            Payload = Container.Resolve<IRepositoryPayload>()
                        };
                })
                .AsSelf()
                .InstancePerLifetimeScope();

            builder
                .RegisterType<StopCommand>()
                .OnActivated(e =>
                {
                    e.Instance.MainViewModel = e.Context.Resolve<MainViewModel>();
                    e.Instance.StopEventFactory =
                        () => new TrakkrEventViewModel
                        {
                            Type = EventType.Stop,
                            Timestamp = DateTime.Now,
                            Payload = Container.Resolve<IRepositoryPayload>()
                        };
                })
                .AsSelf()
                .InstancePerLifetimeScope();

            builder
                .RegisterType<SearchCommand>()
                .OnActivated(e =>
                {
                    e.Instance.MainViewModel = e.Context.Resolve<MainViewModel>();
                    e.Instance.Repositroy = e.Context.Resolve<IRepository<string, IRepositoryPayload>>();
                })
                .AsSelf()
                .InstancePerLifetimeScope();

            Container = builder.Build();
        }
开发者ID:Vittel,项目名称:Trakkr,代码行数:89,代码来源:App.xaml.cs

示例10: Load

 protected override void Load(ContainerBuilder builder)
 {
     var catalog = new TypeCatalog(typeof(GitSourceControlProvider));
     builder.RegisterComposablePartCatalog(catalog);
 }
开发者ID:craiggwilson,项目名称:foundry,代码行数:5,代码来源:SourceControlModule.cs

示例11: UriBuilder

        void IApplicationEventHandler.OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //set up MEF to look for plugins in the /bin/plugins folder
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            string exeLocation=Path.GetDirectoryName(path);
            string pluginPath = Path.Combine(exeLocation, "plugins");
            var pluginCatalog = new DirectoryCatalog(pluginPath);

            var builder = new ContainerBuilder();

            //register all controllers found in this assembly
            builder.RegisterControllers(typeof(CustomerPortalExtensionsApplication).Assembly);

            //add "internal" dependencies via Autofac
            builder.RegisterType<ContactRepository>().As<IContactRepository>();
            builder.RegisterType<ContactSecondaryRepository>().As<IContactSecondaryRepository>();
            builder.RegisterType<ContactAuthenticationHandler>().As<IContactAuthenticationHandler>();
            builder.RegisterType<DefaultContactSynchroniser>().As<IContactSynchroniser>();
            builder.RegisterType<Configuration>().As<IConfigurationService>();
            builder.RegisterType<ContactService>().As<IContactService>();
            builder.RegisterType<MailChimpEmailSubscriptionConnector>().As<IEmailSubscriptionConnector>();
            builder.RegisterType<OrderRepository>().As<IOrderRepository>();
            builder.RegisterType<DiscountHandlerFactory>().As<IDiscountHandlerFactory>();
            builder.RegisterType<EcommerceService>().As<IEcommerceService>();
            builder.RegisterType<OrderCoordinator>().As<IOrderCoordinator>();
            builder.RegisterType<ShippingHandlerFactory>().As<IShippingHandlerFactory>();
            builder.RegisterType<ProductRepository>().As<IProductRepository>();
            builder.RegisterType<VoucherRepository>().As<IVoucherRepository>();
            builder.RegisterType<LocationHandlerFactory>().As<ILocationHandlerFactory>();
            builder.RegisterType<LocationHandler>().As<ILocationHandler>();
            builder.RegisterType<OrderQueueService>().As<IOrderQueueService>();
            builder.RegisterType<EmailSubscriptionsService>().As<IEmailSubscriptionsService>();
            builder.RegisterType<OrderQueue>().As<IOrderQueue>();
            builder.RegisterType<BespokePricingHandlerFactory>().As<IBespokePricingHandlerFactory>();
            builder.RegisterType<AdditionalQueueProcessingHandlerFactory>()
                   .As<IAdditionalQueueProcessingHandlerFactory>();
            builder.RegisterType<Database>()
                   .InstancePerHttpRequest()
                   .WithParameter("connectionString", ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString)
                   .WithParameter("providerName", "System.Data.SqlClient");

            //add in "exeternal" dependencies via MEF
            builder.RegisterComposablePartCatalog(pluginCatalog);

            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:jamesdrever,项目名称:cpx,代码行数:49,代码来源:CustomerPortalApplication.cs


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