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


C# ContainerBuilder.RegisterSource方法代码示例

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


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

示例1: RegisterAutofac

        public static void RegisterAutofac()
        {
            var builder = new ContainerBuilder();

            // Register your MVC controllers.
            // If AutofacConfig's assembly doesn't reference the specific controllers assemblies, use these:
            // builder.RegisterControllers(typeof(MvcApplication).Assembly);
            // builder.RegisterControllers(typeof(BasePublicController).Assembly);
            // builder.RegisterControllers(typeof(BaseAdminController).Assembly);
            // ...
            builder.RegisterControllers(BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToArray());

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // Register services
            RegisterServices(builder);

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Integration with Hangfire
            GlobalConfiguration.Configuration.UseAutofacActivator(container);
        }
开发者ID:mpenchev86,项目名称:ASP.NET-MVC-FinalProject,代码行数:35,代码来源:AutofacConfig.cs

示例2: CreateBuilder

 static ContainerBuilder CreateBuilder()
 {
     var containerBuilder = new ContainerBuilder();
     containerBuilder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
     containerBuilder.RegisterSource(new AutofacMockRegistrationHandler(new MoqMockFactory()));
     return containerBuilder;
 }
开发者ID:ericgutt10,项目名称:Specify,代码行数:7,代码来源:AutofacMoqContainer.cs

示例3: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            var builder = new ContainerBuilder();
            builder.RegisterModelBinderProvider();
            builder.RegisterModule(new AutofacWebTypesModule());
            builder.RegisterSource(new ViewRegistrationSource());
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());

            builder.RegisterType<InMemoryPersonRepository>().As<IPersonRepository>();

            // Use application-scoped variable to mimic in-memory database
            var personDatabase = new List<Person>();
            builder.Register(c => personDatabase).As<List<Person>>();

            IContainer container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            ModelMetadataProviders.Current = new MetadataProvider();
        }
开发者ID:robdmoore,项目名称:ASP.NET-MVC-Terse-Controller-Testing,代码行数:25,代码来源:Global.asax.cs

示例4: Bootstrap

        public static void Bootstrap()
        {
            var builder = new ContainerBuilder();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterAssemblyTypes(typeof (IHandle<>).Assembly)
                .AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(typeof(Denormalizer<>).Assembly)
                .AsImplementedInterfaces();

            //HACK
            builder.RegisterInstance(new Replay.Runner().Rebuild())
                .AsImplementedInterfaces()
                .SingleInstance();

            builder.RegisterModule<EventStoreModule>();
            builder.RegisterType<SignalREventDispatcher>()
                .AsImplementedInterfaces()
                .SingleInstance();

            builder.RegisterType<InProcessCommandProcessor>()
                .AsImplementedInterfaces()
                .SingleInstance();

            builder.RegisterSource(new ContravariantRegistrationSource());

            var container = builder.Build();

            Command.UseContainer(container.BeginLifetimeScope());
            Denormalizer.UseContainer(container.BeginLifetimeScope());
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
开发者ID:kimsk,项目名称:Kanban,代码行数:32,代码来源:Bootstrapper.cs

示例5: Initialize

        public static IContainer Initialize(ContainerBuilder builder)
        {
            // Register all controllers
            builder.RegisterControllers(typeof(Startup).Assembly)
                .OnActivating(e =>
                {
                    var controller = (Controller)e.Instance;
                    controller.TempDataProvider = new CookieTempDataProvider();
                });

            // Register model binders
            builder.RegisterModelBinders(typeof(Startup).Assembly);
            builder.RegisterModelBinderProvider();

            // Register all HTTP abstractions
            builder.RegisterModule<AutofacWebTypesModule>();

            //Register mapper module
            builder.RegisterModule(new MappingModule());

            // Allow property injection in views
            builder.RegisterSource(new ViewRegistrationSource());

            // Allow property injection in action filters
            builder.RegisterFilterProvider();

            // Register all Autofac specific IModule implementations
            builder.RegisterAssemblyModules(typeof(Startup).Assembly);

            return builder.Build();
        }
开发者ID:EnvironmentAgency,项目名称:prsd-iws,代码行数:31,代码来源:AutofacBootstrapper.cs

示例6: Configure

        public void Configure(IComponentRegistry componentRegistry)
        {
            var builder = new ContainerBuilder();

            if (_atomicStorageFactory == null)
            {
                AtomicIsInMemory(strategyBuilder => { });
            }
            if (_streamingRoot == null)
            {
                StreamingIsInFiles(Directory.GetCurrentDirectory());
            }
            if (_tapeStorage == null)
            {
                TapeIsInMemory();
            }

            var core = new AtomicRegistrationCore(_atomicStorageFactory);
            var source = new AtomicRegistrationSource(core);
            builder.RegisterSource(source);
            builder.RegisterInstance(new NuclearStorage(_atomicStorageFactory));
            builder
                .Register(
                    c => new AtomicStorageInitialization(new[] {_atomicStorageFactory}, c.Resolve<ISystemObserver>()))
                .As<IEngineProcess>().SingleInstance();

            builder.RegisterInstance(_streamingRoot);

            builder.RegisterInstance(_tapeStorage);
            builder.RegisterInstance(new TapeStorageInitilization(new[] {_tapeStorage})).As<IEngineProcess>();

            builder.Update(componentRegistry);
        }
开发者ID:higheredgrowth,项目名称:lokad-cqrs,代码行数:33,代码来源:StorageModule.cs

示例7: Register

        public override void Register(ContainerBuilder builder) {
            var testVirtualPathProvider = new StylesheetBindingStrategyTests.TestVirtualPathProvider();

            builder.RegisterInstance(new ShellSettings { Name = "Default" });

            _folders = new ExtensionManagerTests.StubFolders();
            _packagesInRepository = new ModuleStepTest.StubPackagingSourceManager();
            _packageManager = new ModuleStepTest.StubPackageManager();
            builder.RegisterInstance(_folders).As<IExtensionFolders>();
            builder.RegisterType<RecipeExecutionLogger>().AsSelf();
            builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
            builder.RegisterType<FeatureManager>().As<IFeatureManager>();
            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
            builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
            builder.RegisterType<ShellDescriptorManager>().As<IShellDescriptorManager>().SingleInstance();
            builder.RegisterType<ModuleStepTest.StubDataMigrationManager>().As<IDataMigrationManager>();
            builder.RegisterInstance(_packagesInRepository).As<IPackagingSourceManager>();
            builder.RegisterInstance(_packageManager).As<IPackageManager>();
            builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
            builder.RegisterInstance(testVirtualPathProvider).As<IVirtualPathProvider>();
            builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
            builder.RegisterType<ThemeService>().As<IThemeService>();
            builder.RegisterType<StubOrchardServices>().As<IOrchardServices>();
            builder.RegisterType<StubSiteThemeService>().As<ISiteThemeService>();
            builder.RegisterType<ThemeStep>();
            builder.RegisterSource(new EventsRegistrationSource());
        }
开发者ID:Higea,项目名称:Orchard,代码行数:28,代码来源:ThemeStepTest.cs

示例8: SetUpRootScope

        public void SetUpRootScope()
        {
            var builder = new ContainerBuilder();

            // this is needed to allow the Mediator to resolve contravariant handlers (not enabled by default in Autofac)
            builder.RegisterSource(new ContravariantRegistrationSource());

            builder.RegisterAssemblyTypes(typeof (IMediator).Assembly, GetType().Assembly)
                .AsClosedTypesOf(typeof (IRequestHandler<,>))
                .AsImplementedInterfaces();
            
            builder.RegisterType<Mediator>().AsImplementedInterfaces().InstancePerLifetimeScope();

            // to allow ShortBus to resolve lifetime-scoped dependencies properly, 
            // we really can't use the default approach of setting the static (global) dependency resolver, 
            // since that resolves instances from the root scope passed into it, rather than 
            // the current lifetime scope at the time of resolution.  
            // Resolving from the root scope can cause resource leaks, or in the case of components with a 
            // specific scope affinity (AutofacWebRequest, for example) it would fail outright, 
            // since that scope doesn't exist at the root level.
            builder.RegisterType<AutofacDependencyResolver>()
                .AsImplementedInterfaces()
                .InstancePerLifetimeScope();

            RootScope = builder.Build();

            RootScope.ComponentRegistry.Sources.ToList()
                .ForEach(s => Console.WriteLine("{0} ({1})", s.GetType().Name, s));
        }
开发者ID:EquisoftDev,项目名称:ShortBus,代码行数:29,代码来源:AutofacBasicExample.cs

示例9: BuildAutofacContainer

        private static IContainer BuildAutofacContainer(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            // Register your MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            //Register Dependencies
            RegisterIdentityParts(app, builder);
            RegisterImageParts(app, builder);
            RegisterContentParts(app, builder);

            return builder.Build();
        }
开发者ID:RodionKulin,项目名称:ContentManagementBackend,代码行数:27,代码来源:AutofacConfig.cs

示例10: TestGeneralizedProperties

        public void TestGeneralizedProperties()
        {
            var kernel = new ContainerBuilder();
            kernel.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
            var builder = kernel.UseDatenMeisterDotNet(new IntegrationSettings { PathToXmiFiles = "Xmi" });
            using (var scope = builder.BeginLifetimeScope())
            {
                var classifierMethods = scope.Resolve<ClassifierMethods>();
                classifierMethods.Legacy = false;
                var dataLayers = scope.Resolve<DataLayers>();
                var dataLayerLogic = scope.Resolve<DataLayerLogic>();

                // Gets the logic
                var uml = dataLayerLogic.Get<_UML>(dataLayers.Uml);
                var feature = uml.Classification.__Feature;
                var properties = classifierMethods.GetPropertiesOfClassifier(feature).ToList();

                Assert.That(properties.Contains(_UML._Classification._Feature.isStatic), Is.True,
                    "isStatic");
                Assert.That(properties.Contains(_UML._Classification._RedefinableElement.isLeaf), Is.True,
                    "isLeaf (Parent)");
                Assert.That(properties.Contains(_UML._CommonStructure._NamedElement.name), Is.True,
                    "name (Parent of Parent)");
            }
        }
开发者ID:mbrenn,项目名称:datenmeister-new,代码行数:25,代码来源:TestUmlMethods.cs

示例11: Load

 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterType<PaymentService>().As<IPaymentService>();
     builder.RegisterType<FormFactory>().As<IFormFactory>();
     builder.RegisterType<MainWindow>().AsSelf().SingleInstance();
     builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
 }
开发者ID:gofixiao,项目名称:Macsauto-Backup,代码行数:7,代码来源:PresentationModule.cs

示例12: RegisterTypes

        public static void RegisterTypes()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(ContainerConfig).Assembly);

            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();
            builder.RegisterModule<AutofacWebTypesModule>();
            builder.RegisterSource(new ViewRegistrationSource());
            builder.RegisterFilterProvider();

            builder.Register(x => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
            builder.RegisterType<WorkaroundEmailService>().As<IEmailService>().SingleInstance();

            RegisterServices(builder);
            RegisterBackgroundTasks(builder);

            builder.RegisterType<AuctioneerDbContext>().InstancePerRequest();

            builder.RegisterType<BreadcrumbBuilder>().As<IBreadcrumbBuilder>().InstancePerDependency();
            builder.RegisterType<AuthenticationManager>().As<IAuthenticationManager>().InstancePerRequest();
            builder.RegisterType<EmailUserNotifier>().As<IUserNotifier>().SingleInstance();
            builder.RegisterType<LanguageService>().As<ILanguageService>().SingleInstance();
            builder.RegisterType<AuctionService>().As<IAuctionService>().InstancePerRequest().WithParameters(new Parameter[]
            {
                new NamedParameter("photoDirectoryPath",     HostingEnvironment.MapPath("~/Content/UserContent/Auctions/Photos")),
                new NamedParameter("thumbnailDirectoryPath", HostingEnvironment.MapPath("~/Content/UserContent/Auctions/Thumbnails"))
            });

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:Strachu,项目名称:Auctioneer,代码行数:34,代码来源:ContainerConfig.cs

示例13: ConfigureContainer

        public static IContainer ConfigureContainer()
        {
            var _builder = new ContainerBuilder();

            //Call into our data project and let it register it's common services into the same builder
            TypeScript.Demo.Data.AutofacConfig.RegisterCommonServices(_builder);


            //This code is fairly stock code demonstrating how to tightly integrate Autofac with MVC and WebAPI
            _builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            _builder.RegisterModelBinders(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            _builder.RegisterModelBinderProvider();
            _builder.RegisterModule(new AutofacWebTypesModule());
            _builder.RegisterSource(new ViewRegistrationSource());
            _builder.RegisterFilterProvider();
            _builder.RegisterWebApiModelBinders(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            _builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();

            var _container = _builder.Build();

            // Tell ASP.NET MVC to use Autofac to resolve components
            DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));

            // Create the depenedency resolver for web API
            var resolver = new AutofacWebApiDependencyResolver(_container);

            // Configure Web API with the dependency resolver.
            GlobalConfiguration.Configuration.DependencyResolver = resolver;

            return _container;
        }
开发者ID:ArchitectNow,项目名称:TypeScript.Demo,代码行数:31,代码来源:AutofacConfig.cs

示例14: ConfigureContainer

        public static void ConfigureContainer()
        {
            var builder = new ContainerBuilder();

            // Register dependencies in controllers
            builder.RegisterControllers(typeof(AutofacConfig).Assembly);

            // Register dependencies in filter attributes
            builder.RegisterFilterProvider();

            // Register dependencies in custom views
            builder.RegisterSource(new ViewRegistrationSource());

            // Register our Data dependencies
            builder.RegisterModule(new Application.Composition.CoreModule());
            builder.RegisterModule(new Application.Composition.ApplicationModule());
            builder.RegisterModule(new Application.Composition.MessagingModule());
            builder.RegisterModule(new PersistenceModule()
            {
                ConnectionStringOrName = "name=ClaimConnectionString"
            });

            var config = GlobalConfiguration.Configuration;
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(config);

            var container = builder.Build();

            // Set MVC DI resolver to use our Autofac container
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:gengle,项目名称:ddd-vehicle-claims,代码行数:32,代码来源:AutofacConfig.cs

示例15: RegisterServices

        protected void RegisterServices()
        {
            var tenantIdStrategy = new RouteDataItemTenantIdentificationStrategy("tenant");

            var builder = new ContainerBuilder();

            // Register your MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // Create the multitenant container and the tenant overrides.
            var mtc = new MultitenantContainer(tenantIdStrategy, builder.Build());
            AddTenant(mtc, "a");
            AddTenant(mtc, "b");

            DependencyResolver.SetResolver(new AutofacDependencyResolver(mtc));
        }
开发者ID:mppa-git,项目名称:aspnet4-multitenant-framework,代码行数:29,代码来源:Global.asax.cs


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