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


C# ContainerBuilder.RegisterTypes方法代码示例

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


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

示例1: ConfigureServices

        protected override void ConfigureServices()
        {
            var builder = new ContainerBuilder();
            List<Type> typeCollection = GetTypesToRegister();

            // Runtime Services
            builder.RegisterType<CommandManager>().As<ICommandManager>();
            builder.RegisterType<NotificationManager>().As<INotificationCenter>().SingleInstance();
            builder.RegisterTypes(typeCollection.Where(type => type.IsAssignableTo<IInputCommand>()).ToArray())
                .AsImplementedInterfaces()
                .AsSelf();

            // Marker Services
            builder.RegisterTypes(typeCollection.Where(type => type.IsAssignableTo<IRepository>()).ToArray()).AsImplementedInterfaces();
            builder.RegisterTypes(typeCollection.Where(type => type.IsAssignableTo<IService>()).ToArray()).AsImplementedInterfaces();
            builder
                .RegisterTypes(typeCollection.Where(type => type.IsAssignableTo<IComponent>()).ToArray())
                .AsImplementedInterfaces();
            builder
                .RegisterTypes(typeCollection.Where(type => type.IsAssignableTo<IGameComponent>()).ToArray())
                .AsImplementedInterfaces()
                .OnActivating(args => ((IGameComponent)args.Instance).SetNotificationManager(this.container.Resolve<INotificationCenter>()));

            // Server Services
            builder.RegisterType<DefaultServer>().As<IServer>();
            builder.RegisterType<ServerConfiguration>().As<IServerConfiguration>();

            container = builder.Build();

            CommandManagerFactory.SetFactory(() => container.Resolve<ICommandManager>());
            CharacterFactory.SetFactory(
                game => this.container.Resolve<IPlayer>(new TypedParameter(typeof(IGame), game)));

            CommandFactory.SetFactory(CreateCommandFromAlias);
        }
开发者ID:ramseur,项目名称:MudDesigner,代码行数:35,代码来源:DefaultServerBootstrap.cs

示例2: Load

        protected override void Load(ContainerBuilder builder)
        {
            logger.Information("Hi from pingo.filters Autofac.Load!");
            var assembly = this.GetType().GetTypeInfo().Assembly;
            var derivedTypes = TypeHelper<ActionFilterAttribute>.FindDerivedTypes(assembly).ToArray();
            var derivedTypesName = derivedTypes.Select(x => x.GetTypeInfo().Name);
            logger.Information("Found these types: {DerivedTypes}", derivedTypesName);

            builder.RegisterTypes(derivedTypes).SingleInstance();


            derivedTypes = TypeHelper<MiddlewarePlugin>.FindDerivedTypes(assembly).ToArray();
            derivedTypesName = derivedTypes.Select(x => x.GetTypeInfo().Name);
            logger.Information("Found these types: {DerivedTypes}", derivedTypesName);
            builder.RegisterTypes(derivedTypes).SingleInstance();


            /*

            builder.RegisterType<AuthActionFilter>().SingleInstance();
            builder.RegisterType<LogFilter>().SingleInstance();
            builder.RegisterType<LogFilter2>().SingleInstance();
            builder.RegisterType<LogFilter3>().SingleInstance();
            */
        }
开发者ID:ghstahl,项目名称:vNext.Jan2016Web,代码行数:25,代码来源:AutofacModule.cs

示例3: Register

        public static void Register()
        {
            //初始化一个autofac容器
               var autoConainer = new ContainerBuilder();
               //告诉autofac查找控制器类需要扫描的程序集
               autoConainer.RegisterControllers(Assembly.Load("Test"));

               //将指定程序集下的类的实例保存到autofac容器 用于注入
               autoConainer.RegisterTypes(Assembly.Load("DAL").GetTypes()).AsImplementedInterfaces();
               autoConainer.RegisterTypes(Assembly.Load("BLL").GetTypes()).AsImplementedInterfaces();

              var c=autoConainer.Build();
               //告诉mvc底层  创建控制器由autofac 容器接管
               System.Web.Mvc.DependencyResolver.SetResolver(new AutofacDependencyResolver(c));
        }
开发者ID:aa1356889,项目名称:git,代码行数:15,代码来源:AutoFacRegister.cs

示例4: Load

 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterTypes(
         ThisAssembly.GetExportedTypes()
             .Where(x => x.Namespace != null && x.Namespace.EndsWith("Core"))
             .ToArray());
 }
开发者ID:Grinderofl,项目名称:ImageHosting,代码行数:7,代码来源:RegistrationModule.cs

示例5: Main

        static void Main(string[] args)
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType<Cpu>().As<ICpu>().SingleInstance();
            containerBuilder.RegisterType<Emulator>().As<IEmulator>();
            containerBuilder.RegisterType<Memory>().As<IMemory>().SingleInstance();
            containerBuilder.RegisterType<Ppu>().As<IPpu>();

            var instructionTypes = Assembly.GetExecutingAssembly().GetTypes().Where(f => typeof(IInstruction).IsAssignableFrom(f) && !f.IsAbstract).ToArray();

            containerBuilder.RegisterTypes(instructionTypes)
                .As<IInstruction>();

            var container = containerBuilder.Build();

            var emulator = container.Resolve<IEmulator>();
            var memory = container.Resolve<IMemory>();
            memory.SetCartridge(new Cartridge("../../roms/nestest.nes"));
            emulator.Reset();
            for (;;)
            {
                emulator.Step();
            }
        }
开发者ID:Cyberlane,项目名称:LeetNES,代码行数:25,代码来源:Program.cs

示例6: MainWindow

        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        public MainWindow()
        {
            this.InitializeComponent();

            var builder = new ContainerBuilder();
            builder.RegisterTypes(
                    typeof(RelayCloudBlobStorageProvider),
                    typeof(Channel),
                    typeof(PostalService),
                    typeof(OwnEndpointServices),
                    typeof(DirectEntryAddressBook),
                    typeof(HttpClientWrapper))
                .AsSelf()
                .AsImplementedInterfaces()
                .SingleInstance()
                .PropertiesAutowired();
            builder.RegisterType(
                typeof(ChatroomWindow))
                .AsSelf()
                .PropertiesAutowired();
            builder.Register(ctxt => ctxt.Resolve<HttpClientWrapper>().Client);
            builder.RegisterInstance(this)
                .AsSelf()
                .PropertiesAutowired();
            this.container = builder.Build();
            this.container.Resolve<MainWindow>();  // get properties satisfied

            this.MessageRelayService.BlobPostUrl = new Uri(ConfigurationManager.ConnectionStrings["RelayBlobService"].ConnectionString);
            this.MessageRelayService.InboxServiceUrl = new Uri(ConfigurationManager.ConnectionStrings["RelayInboxService"].ConnectionString);
        }
开发者ID:AArnott,项目名称:IronPigeon,代码行数:33,代码来源:MainWindow.xaml.cs

示例7: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            // Register the SignalR hubs.
            builder.RegisterHubs(Assembly.GetExecutingAssembly());

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .Where(t => t.Name.EndsWith("Repository", StringComparison.Ordinal))
                .AsImplementedInterfaces();

            builder.RegisterType<FeatureApplicationServices>().AsImplementedInterfaces();
            builder.RegisterType<CommandSender>().As<ICommandSender>();

            var innerBuilder = new ContainerBuilder();
            innerBuilder.RegisterTypes(ThisAssembly.GetTypes().Where(_ => typeof(IHubBroadcasterFor).IsAssignableFrom(_)).ToArray())
                .As<IHubBroadcasterFor>();

            innerBuilder.RegisterTypes(ThisAssembly.GetTypes().Where(_ => typeof(IDatabaseBroadcasterFor).IsAssignableFrom(_)).ToArray())
                .As<IDatabaseBroadcasterFor>();

            innerBuilder.RegisterTypes(ThisAssembly.GetTypes().Where(_ => typeof(IHistoryBroadcasterFor).IsAssignableFrom(_)).ToArray())
                .As<IHistoryBroadcasterFor>();

            IContainer innerContainer = innerBuilder.Build();
            var eventHandlers = new IEventHandler[] {
                new DatabaseEventHandler(innerContainer.Resolve<IEnumerable<IDatabaseBroadcasterFor>>()),
                new HubEventHandler(innerContainer.Resolve<IEnumerable<IHubBroadcasterFor>>()),
                new HistoryEventHandler(innerContainer.Resolve<IEnumerable<IHistoryBroadcasterFor>>())
            };
            var dispatcher = new NEventStoreDispatcher(eventHandlers);

            var nEventStore =
                Wireup.Init()
                    .LogToOutputWindow()
                    .UsingSqlPersistence("FeatureBeeContext")
                    .WithDialect(new MsSqlDialect())
                    .InitializeStorageEngine()
                    // .EnlistInAmbientTransaction()
                    .UsingJsonSerialization()
                    .UsingSynchronousDispatchScheduler()
                    .DispatchTo(new DelegateMessageDispatcher(dispatcher.DispatchCommit))
                    .Build();

            builder.RegisterInstance(nEventStore);
        }
开发者ID:cw2018,项目名称:FeatureBee,代码行数:47,代码来源:DIConfiguration.cs

示例8: RegisterDependencyTypes

 /// <summary>
 /// 实现依赖注入接口<see cref="IDependency"/>实现类型的注册
 /// </summary>
 /// <param name="types">要注册的类型集合</param>
 protected void RegisterDependencyTypes(Type[] types)
 {
     ContainerBuilder builder = new ContainerBuilder();
     var builderSource = builder.RegisterTypes(types)
         .AsSelf()
         .AsImplementedInterfaces()
         .InstancePerLifetimeScope();//所有实现IDependency的注册为InstancePerLifetimeScope生命周期
     builder.Update(Container);
 }
开发者ID:zengfanlin,项目名称:MVC5WithAutofac,代码行数:13,代码来源:IocInitializeConstructor.cs

示例9: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterTypes(ThisAssembly);

            builder.Register<Func<Type, object>>(context =>
            {
                var componentContext = context.Resolve<IComponentContext>();
                return serviceType => componentContext.Resolve(serviceType);
            });
        }
开发者ID:tomekjanicki,项目名称:architecture2,代码行数:10,代码来源:DependencyModule.cs

示例10: Initialize

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

            var loggerConfigurator = new LoggerConfigurator(_logLevel);
            loggerConfigurator.Configure();
            var logger = loggerConfigurator.GetLogger();

            builder.RegisterInstance<ILog>(logger).Exported(x => x.As<ILog>());
            builder.RegisterType<ReplConsole>().As<IConsole>().Exported(x => x.As<IConsole>());

            var types = new[]
                {
                    typeof (ScriptHostFactory),
                    typeof (FileSystem),
                    typeof (PackageAssemblyResolver),
                    typeof (PackageContainer),
                    typeof (FilePreProcessor),
                    typeof (ScriptPackResolver),
                    typeof (NugetInstallationProvider),
                    typeof (PackageInstaller),
                    typeof (AssemblyName)
                };

            builder.RegisterTypes(types).AsImplementedInterfaces();

            if (_debug)
            {
                builder.RegisterType<DebugScriptExecutor>().As<IScriptExecutor>();
                builder.RegisterType<RoslynScriptDebuggerEngine>().As<IScriptEngine>();
                builder.RegisterType<FSharpScriptEngine>().As<IScriptEngine>();
            }
            else
            {
                builder.RegisterType<ScriptExecutor>().As<IScriptExecutor>();
                builder.RegisterType<RoslynScriptEngine>().As<IScriptEngine>();
                builder.RegisterType<FSharpScriptEngine>().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:7sharp9,项目名称:scriptcs,代码行数:53,代码来源:CompositionRoot.cs

示例11: Load

		protected override void Load(ContainerBuilder builder)
		{
			base.Load(builder);

			builder.RegisterType<Fixture>().SingleInstance();

			builder.RegisterTypes(
				typeof(StringGenerator))
				.SingleInstance();

			builder.RegisterType<OperationGenerator>().SingleInstance();
		}
开发者ID:ldominate,项目名称:Legacy,代码行数:12,代码来源:GeneratorModule.cs

示例12: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<AutofacApplicationBus>()
                .As<IApplicationBus>()
                .SingleInstance();

            builder.RegisterGeneric(typeof (NullHandler<,>))
                .As(typeof (IRequestHandler<,>));

            builder.RegisterTypes(_handlerTypes.Distinct()
                .ToArray())
                .AsImplementedInterfaces();
        }
开发者ID:jrnail23,项目名称:ConfigCentral,代码行数:13,代码来源:ApplicationBusPlumbingModule.cs

示例13: ContainerManagment

        /// <summary>
        /// 容器注册管理
        /// </summary>
        static void ContainerManagment()
        {
            var builder = new ContainerBuilder();
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            //builder.RegisterType<UserRepository>().As<IUserRepository>();
            builder.RegisterTypes(Assembly.Load("MvcEFTest.Autofac.Demo.Repositories").GetTypes()).AsImplementedInterfaces();

            // Change controller action parameter injection by changing web.config.
            builder.RegisterType<ExtensibleActionInvoker>().As<IActionInvoker>().InstancePerRequest();

            IContainer container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:SimpleSimple,项目名称:MvcEFTest,代码行数:18,代码来源:Global.asax.cs

示例14: Program

        static Program()
        {
            //discover types
            new DirectoryCatalog(".");

            //bootstrap everything
            var builder = new ContainerBuilder();

            builder.RegisterType<FileEventSerializer>().As<IEventSerializer>();
            builder.RegisterType<EventService>().As<IEventService>();
            builder.RegisterType<ConsoleLogger>().As<ILogger>();
            builder.RegisterGeneric(typeof(LoggingAspect<>)).As(typeof(IAspect<>));
            builder.RegisterGeneric(typeof(TransactionAspect<>)).As(typeof(IAspect<>));

            //find and register all features
            var features = from feat in AppDomain.CurrentDomain.GetAssemblies().SelectMany( a=> a.GetTypes())
                          where !feat.IsInterface && !feat.IsAbstract
                          where (from @if in feat.GetInterfaces() where @if.IsGenericType select @if.GetGenericTypeDefinition()).FirstOrDefault() == typeof(IFeature<>)
                          select feat;
            builder.RegisterTypes(features.ToArray());

            var container = builder.Build();

            _bus = container.Resolve<IEventService>();
            _bus.CanRead = false;
            _bus.CanWrite = true;

            var logger = container.Resolve<ILogger>();

            //find all commands
            //var commands = from cmd in AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes())
            //               where !cmd.IsInterface && !cmd.IsAbstract && typeof(ICommand).IsAssignableFrom(cmd)
            //               select cmd;

            ////register/subscribe all commands with dmain handlers
            //foreach (var cmd in commands)
            //{
            //    var createHandler = typeof(DomainServicesExtensions).GetMethod("CreateHandler", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(cmd);
            //    var handler = createHandler.Invoke(null, new[] { container });

            //    var subscribe = typeof(EventService).GetMethod("Subscribe").MakeGenericMethod(cmd);
            //    subscribe.Invoke(_bus, new[] { handler });
            //}
        }
开发者ID:evisar,项目名称:nocqrs,代码行数:44,代码来源:Program.cs

示例15: Main

 private static void Main(string[] args)
 {
     var builder = new ContainerBuilder();
     builder.RegisterTypes(
             typeof(Program),
             typeof(RelayCloudBlobStorageProvider),
             typeof(Channel),
             typeof(OwnEndpointServices),
             typeof(DirectEntryAddressBook),
             typeof(HttpClientWrapper))
         .AsSelf()
         .AsImplementedInterfaces()
         .SingleInstance()
         .PropertiesAutowired();
     builder.Register(ctxt => ctxt.Resolve<HttpClientWrapper>().Client);
     var container = builder.Build();
     var program = container.Resolve<Program>();
     program.DoAsync().GetAwaiter().GetResult();
 }
开发者ID:AArnott,项目名称:IronPigeon,代码行数:19,代码来源:Program.cs


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