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


C# ContainerBuilder.RegisterGeneratedFactory方法代码示例

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


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

示例1: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<BleMoCoBusCommService>()
                .As<IMoCoBusCommService>();

            builder.RegisterType<MoCoBusProtocolService>()
                .As<IMoCoBusProtocolService>();

            builder.RegisterType<MoCoBusProtocolMainService>()
                .As<IMoCoBusProtocolMainService>();

            builder.RegisterType<MoCoBusProtocolCameraService>()
                .As<IMoCoBusProtocolCameraService>();

            builder.RegisterType<MoCoBusProtocolMotorService>()
                .As<IMoCoBusProtocolMotorService>();

            builder.RegisterGeneratedFactory<MoCoBusProtocolMotorServiceFactoryDelegate>(
                new TypedService(typeof(IMoCoBusProtocolMotorService)));

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

            builder.RegisterType<DeviceViewModel>();

            builder.RegisterType<ModeAstroViewModel>();
        }
开发者ID:milindur,项目名称:MdkControlApp,代码行数:27,代码来源:CoreModule.cs

示例2: CanBuildWithAutofac

        public void CanBuildWithAutofac()
        {
            var builder = new ContainerBuilder();
            builder.Register<LevelPiece>().FactoryScoped();
            builder.RegisterGeneratedFactory<LevelPiece.Factory>(new TypedService(typeof(LevelPiece)));
            builder.Register<DumbLevelLoader>().As<ILevelLoader>().SingletonScoped();
            builder.Register<Level>().As<ILevel>().SingletonScoped();
            
            builder.Register<LevelView>();
            ISpriteBatch spriteBatch = MockRepository.GenerateStub<ISpriteBatch>();
            builder.Register<ISpriteBatch>(spriteBatch);
            ITexture texture = MockRepository.GenerateStub<ITexture>();
            builder.Register<ITexture>(texture);

            var container = builder.Build();

            LevelView levelView = container.Resolve<LevelView>(new TypedParameter(typeof(ICamera), null));

            Assert.IsNotNull(levelView);
        }
开发者ID:zakvdm,项目名称:Frenetic,代码行数:20,代码来源:LevelTests.cs

示例3: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.Register((container, parameters) =>
            {
                var pos = parameters.Named<Vector2>("position");
                var size = parameters.Named<Vector2>("size");
                var physics = container.Resolve<IPhysicsComponent>(new NamedParameter("size", size));
                physics.Position = pos;
                return new LevelPiece(physics);
            }).FactoryScoped();

            builder.RegisterGeneratedFactory<LevelPiece.Factory>(new TypedService(typeof(LevelPiece)));
            builder.Register<DumbLevelLoader>().As<ILevelLoader>().ContainerScoped();
            builder.Register<Frenetic.Gameplay.Level.Level>().As<ILevel>().ContainerScoped();
            builder.Register<LevelController>().ContainerScoped();
            builder.Register<LevelView>().ContainerScoped();

            builder.Register<VisibilityView>().ContainerScoped();

            builder.Register<PlayerRespawner>().As<IPlayerRespawner>().SingletonScoped();
        }
开发者ID:zakvdm,项目名称:Frenetic,代码行数:21,代码来源:LevelModule.cs

示例4: Inject

        public static void Inject(ContainerBuilder builder, string projectPath, SyncUIFeatures syncDialogFeatures)
        {
            //TODO: shouldn't we have people provide the whole project configuration? Otherwise, we have an empty set of
            //include/exlcude patterns, so new files aren't going to get added.  Maybe if we're going to do that, it
            //doesn't make sense for this to do the injecting at all... maybe the client should do it.  Similar issue
            //below, with SyncUIFeatures

            builder.Register<ProjectFolderConfiguration>(
               c => new ProjectFolderConfiguration(projectPath)).InstancePerLifetimeScope();

            builder.RegisterType<NavigateToRecordEvent>().InstancePerLifetimeScope();

            builder.RegisterInstance(new NullProgress()).As<IProgress>();
            builder.Register<Synchronizer>(c => Chorus.sync.Synchronizer.FromProjectConfiguration(
                                                    c.Resolve<ProjectFolderConfiguration>(), new NullProgress()));
            builder.Register<HgRepository>(c => HgRepository.CreateOrUseExisting(projectPath, new NullProgress())).InstancePerLifetimeScope();

            //this is a sad hack... I don't know how to simly override the default using the container,
            //which I'd rather do, and just leave this to pushing in the "normal"
            builder.Register<SyncUIFeatures>(c => syncDialogFeatures).As<SyncUIFeatures>().SingleInstance();

            builder.RegisterInstance(new EmbeddedMessageContentHandlerRepository());

            builder.RegisterInstance(ChorusFileTypeHandlerCollection.CreateWithInstalledHandlers()).SingleInstance();

            builder.RegisterType<SyncPanel>().InstancePerLifetimeScope();
            builder.RegisterType<SyncControlModel>().InstancePerLifetimeScope();
            builder.RegisterType<SyncDialog>().InstancePerDependency();//NB: was FactoryScoped() before switch to autofac 2, which corresponds to this InstancePerDependency
            builder.RegisterGeneratedFactory<SyncDialog.Factory>().InstancePerLifetimeScope();
            builder.RegisterType<Chorus.UI.Misc.TroubleshootingView>().InstancePerLifetimeScope();

            RegisterSyncStuff(builder);
            RegisterReviewStuff(builder);
            RegisterSettingsStuff(builder);

            InjectNotesUI(builder);
        }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:37,代码来源:ChorusUIComponentsInjector.cs

示例5: InjectNotesUI

        /// <summary>
        /// Only call this directly if you're not using the synching stuff (e.g., testing the notes UI)
        /// </summary>
        /// <param name="builder"></param>
        public static void InjectNotesUI(ContainerBuilder builder)
        {
            builder.RegisterType<MessageSelectedEvent>().InstancePerLifetimeScope();
            builder.RegisterType<Chorus.notes.EmbeddedMessageContentHandlerRepository>().InstancePerLifetimeScope();
            builder.RegisterType<NotesInProjectViewModel>().InstancePerLifetimeScope();
            builder.RegisterType<NotesInProjectView>().InstancePerLifetimeScope();
            builder.RegisterType<Chorus.UI.Notes.AnnotationEditorView>().InstancePerLifetimeScope();
            builder.RegisterType<Chorus.UI.Notes.AnnotationEditorModel>().InstancePerDependency();
            builder.RegisterType<NotesBrowserPage>().InstancePerLifetimeScope();
            builder.Register<StyleSheet>(c => StyleSheet.CreateFromDisk()).InstancePerLifetimeScope();
            builder.RegisterGeneratedFactory<AnnotationEditorModel.Factory>().InstancePerLifetimeScope();
            builder.RegisterType<NotesBarModel>().InstancePerLifetimeScope();
            builder.RegisterGeneratedFactory<NotesBarModel.Factory>().InstancePerLifetimeScope();
            builder.RegisterType<NotesBarView>().InstancePerLifetimeScope();
            builder.RegisterGeneratedFactory<NotesBarView.Factory>().InstancePerLifetimeScope();

            builder.RegisterGeneratedFactory<NotesInProjectView.Factory>().InstancePerLifetimeScope();
            builder.RegisterGeneratedFactory<NotesInProjectViewModel.Factory>().InstancePerLifetimeScope();
            builder.RegisterGeneratedFactory<NotesBrowserPage.Factory>().InstancePerLifetimeScope();
        }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:24,代码来源:ChorusUIComponentsInjector.cs

示例6: RegisterReviewStuff

        internal static void RegisterReviewStuff(ContainerBuilder builder)
        {
            builder.RegisterInstance(new ConsoleProgress( )).As<IProgress>();
            builder.RegisterType<RevisionInspector>().InstancePerLifetimeScope();
            builder.RegisterType<ChangesInRevisionModel>().InstancePerLifetimeScope();
            builder.RegisterType<HistoryPage>().InstancePerLifetimeScope();
            builder.RegisterGeneratedFactory<HistoryPage.Factory>();

            builder.RegisterType<ChangesInRevisionView>().InstancePerLifetimeScope();
            builder.RegisterType<ChangeReportView>().InstancePerLifetimeScope();

            //review-related events
            builder.RegisterType<RevisionSelectedEvent>().InstancePerLifetimeScope();
            builder.RegisterType<ChangedRecordSelectedEvent>().InstancePerLifetimeScope();

            builder.RegisterType<RevisionInRepositoryModel>().InstancePerLifetimeScope();
            builder.RegisterGeneratedFactory<RevisionInRepositoryModel.Factory>();
            builder.RegisterType<RevisionsInRepositoryView>().InstancePerLifetimeScope();
        }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:19,代码来源:ChorusUIComponentsInjector.cs

示例7: BuildContainer

        IContainer BuildContainer()
        {
            var builder = new ContainerBuilder();

            #region XNA
            // NOTE: This is order sensitive because disposing of the GraphicsDeviceManager also disposes the ContentManager, and we don't want that to happen twice...
            // Needs to be fixed somehow...
            builder.Register<ContentManager>(Content).SingletonScoped();
            builder.Register<XnaContentManager>(new XnaContentManager(Content)).As<IContentManager>().SingletonScoped();
            builder.Register<XnaGame>(new XnaGame(this)).As<IGame>().SingletonScoped();
            builder.Register<GraphicsDevice>(graphics.GraphicsDevice).SingletonScoped();
            #endregion

            #region Engine
            builder.Register<Quitter>().SingletonScoped();
            builder.Register<SettingsPersister>().As<ISettingsPersister>().SingletonScoped();

            builder.Register<Frenetic.Engine.TimerController>().ContainerScoped();
            builder.Register((c, p) =>
                                {
                                    var timer = new Frenetic.Engine.Timer();
                                    c.Resolve<TimerController>().Tick += timer.UpdateElapsedTime;
                                    return timer;
                                }).As<ITimer>().FactoryScoped();

            //builder.Register<log4net.ILog>((c, p) => log4net.LogManager.GetLogger(p.TypedAs<Type>())).FactoryScoped();
            builder.Register<log4netLoggerFactory>().As<ILoggerFactory>().SingletonScoped();
            #endregion

            #region Menus
            builder.Register<ScreenManager>((c, p) => new ScreenManager(this, Content, c.Resolve<MenuInputState>())).SingletonScoped();
            builder.Register<MenuInputState>().SingletonScoped();
            builder.Register<ScreenFactory>().As<IScreenFactory>().SingletonScoped();
            builder.Register<MainMenuScreen>().SingletonScoped();
            #endregion

            #region Networking
            builder.Register(new NetServer(new NetConfiguration("Frenetic")));
            builder.Register(new NetClient(new NetConfiguration("Frenetic")));
            builder.Register<NetServerWrapper>().As<INetServer>().ContainerScoped();
            builder.Register<NetClientWrapper>().As<INetClient>().ContainerScoped();
            builder.Register<LidgrenServerNetworkSession>().As<IServerNetworkSession>().ContainerScoped();
            builder.Register<LidgrenServerMessageSender>().As<IServerMessageSender>().ContainerScoped();
            builder.Register<LidgrenClientNetworkSession>().As<IClientNetworkSession>().ContainerScoped();
            builder.Register<IncomingMessageQueue>().As<IIncomingMessageQueue>().ContainerScoped();
            builder.Register<OutgoingMessageQueue>().As<IOutgoingMessageQueue>().ContainerScoped();

            builder.Register<LocalClient>().ContainerScoped();
            builder.Register<Client>().FactoryScoped();
            builder.RegisterGeneratedFactory<Client.Factory>(new TypedService(typeof(Client)));
            builder.Register<ServerSideClientFactory>().ContainerScoped();
            builder.Register<ClientSideClientFactory>().ContainerScoped();

            builder.Register<ClientInputSender>().ContainerScoped();
            builder.Register<ClientInputProcessor>().ContainerScoped();

            builder.Register<ClientStateTracker>().As<IClientStateTracker>().ContainerScoped();
            builder.Register<SnapCounter>().As<ISnapCounter>().ContainerScoped();

            builder.Register<NetworkPlayerProcessor>().As<INetworkPlayerProcessor>().ContainerScoped();
            #endregion

            #region Graphics
            builder.Register<Viewport>(graphics.GraphicsDevice.Viewport);
            builder.Register<SpriteFont>((c, p) => c.Resolve<ScreenManager>().Font);
            builder.Register<SpriteBatch>((c, p) => c.Resolve<ScreenManager>().SpriteBatch);
            builder.Register<XnaSpriteBatch>().As<ISpriteBatch>().FactoryScoped();
            builder.Register<XnaTexture>().As<ITexture>().FactoryScoped();
            builder.Register<XnaFont>().As<IFont>().FactoryScoped();
            builder.Register<XnaPrimitiveDrawer>().As<IPrimitiveDrawer>().ContainerScoped();
            builder.Register<BubbleTextDrawer>((c, p) => new BubbleTextDrawer(c.Resolve<IContentManager>().Load<IFont>("Fonts/BubbleText"))).As<IBubbleTextDrawer>().SingletonScoped();
            #endregion

            #region GameSession
            builder.Register<GameSessionFactory>().As<IGameSessionFactory>().SingletonScoped();
            builder.Register<GameSession>().As<IGameSession>().ContainerScoped();
            builder.Register<GameSessionController>().ContainerScoped();
            builder.Register<GameSessionView>().ContainerScoped();
            #endregion

            #region Player
            builder.RegisterModule(new PlayerModule() { ScreenWidth = _screenWidth, ScreenHeight = _screenHeight });
            #endregion

            #region Physics
            builder.RegisterModule(new PhysicsModule() { Gravity = _gravity });
            #endregion

            #region Weapons
            builder.RegisterModule(new WeaponsModule() { ContentManager = new ContentManager(this.Services, "Content"), GraphicsDeviceService = this.graphics });
            #endregion

            #region Level
            builder.RegisterModule(new LevelModule());
            #endregion

            #region HUD
            builder.RegisterModule(new OverlaysModule() { ScreenSize = new Vector2(_screenWidth, _screenHeight), InputBoxHeight = 24, ContentManager = this.Content });
            #endregion

//.........这里部分代码省略.........
开发者ID:zakvdm,项目名称:Frenetic,代码行数:101,代码来源:FreneticGame.cs

示例8: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.Register((container, parameters) =>
                {
                    Renderer renderer = new SpriteBatchRenderer() { BlendMode = SpriteBlendMode.Additive, GraphicsDeviceService = this.GraphicsDeviceService };
                    //Renderer renderer = new SpriteBatchRenderer() { BlendMode = SpriteBlendMode.AlphaBlend, GraphicsDeviceService = this.GraphicsDeviceService };
                    renderer.LoadContent(this.ContentManager);
                    return renderer;
                }).SingletonScoped();

            builder.Register((container, parameters) =>
                {
                    var emitterName = parameters.TypedAs<string>();
                    Emitter emitter = this.ContentManager.Load<Emitter>("Effects\\" + emitterName);
                    emitter.LoadContent(this.ContentManager);
                    emitter.Initialize();
                    System.Diagnostics.Debug.Assert(emitter.ParticleTexture != null, "Emitter MUST have a texture otherwise nothing will be drawn!", "Probably need to specify the ParticleTextureAssetName xml tag in the Effect .em file.");
                    return emitter;
                }).FactoryScoped();

            builder.Register<MercuryLineParticleEffect>
                (c => new MercuryLineParticleEffect
                    (
                        c.Resolve<Renderer>(),
                        c.Resolve<Emitter>(new TypedParameter(typeof(string), "line"))
                    )).As<ILineEffect>().SingletonScoped();
            builder.Register<MercuryPointParticleEffect>
                (c => new MercuryPointParticleEffect
                    (
                        c.Resolve<Renderer>(),
                        c.Resolve<Emitter>(new TypedParameter(typeof(string), "point")),
                        c.Resolve<Emitter>(new TypedParameter(typeof(string), "explosion"))
                    )).As<IEffect>().SingletonScoped();
            builder.RegisterGeneratedFactory<Frenetic.Graphics.Effects.LineEffect.Factory>(new TypedService(typeof(ILineEffect)));
            builder.Register<EffectUpdater>().ContainerScoped();

            // WEAPONS:
            builder.Register<RailGun>().As<RailGun>().FactoryScoped();
            builder.Register<RocketLauncher>().As<RocketLauncher>().FactoryScoped();

            builder.Register((container) =>
                {
                    Dictionary<WeaponType, IWeapon> weapons = new Dictionary<WeaponType, IWeapon>();
                    weapons.Add(WeaponType.RailGun, container.Resolve<RailGun>());
                    weapons.Add(WeaponType.RocketLauncher, container.Resolve<RocketLauncher>());

                    return new WeaponList(weapons);
                }).As<IWeapons>().FactoryScoped();
            
            builder.Register<Rocket>().FactoryScoped();
            builder.RegisterGeneratedFactory<Rocket.Factory>(new TypedService(typeof(Rocket)));

            builder.Register<RocketLauncherView>().FactoryScoped();
            builder.Register<RailGunView>().FactoryScoped();

            builder.Register((container) =>
                {
                    List<IWeaponView> weaponViews = new List<IWeaponView>() { container.Resolve<RocketLauncherView>(), container.Resolve<RailGunView>() };
                    return new WeaponDrawer(container.Resolve<IPlayerController>(), container.Resolve<IPlayerList>(), weaponViews);
                }).As<IWeaponDrawer>().ContainerScoped();
        }
开发者ID:zakvdm,项目名称:Frenetic,代码行数:61,代码来源:WeaponsModule.cs


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