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>(); }
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); }
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(); }
private static void SetupPatterns(Autofac.ContainerBuilder builder) { var serverModels = (from asm in NGS.Utility.AssemblyScanner.GetAssemblies() let type = asm.GetType("SystemBoot.Configuration") where type != null && type.GetMethod("Initialize") != null select asm) .ToList(); builder.RegisterGeneratedFactory <NGS.DomainPatterns.DomainModel.Factory>(); builder.RegisterType <NGS.DomainPatterns.DomainModel>(); builder.Register(c => c.Resolve <NGS.DomainPatterns.DomainModel.Factory>()(serverModels)).As <IDomainModel>().SingleInstance(); builder.RegisterType <DomainTypeResolver>().As <ITypeResolver>().SingleInstance(); builder.RegisterType <ServiceLocator>().As <IServiceLocator, IServiceProvider>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(WeakCache <>)).As(typeof(IDataCache <>)).InstancePerLifetimeScope(); builder.RegisterType <DomainEventSource>().As <IDomainEventSource>().InstancePerLifetimeScope(); builder.RegisterType <DomainEventStore>().As <IDomainEventStore>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(SingleDomainEventSource <>)).As(typeof(IDomainEventSource <>)).InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(RegisterChangeNotifications <>)).As(typeof(IObservable <>)).SingleInstance(); builder.RegisterType <DataContext>().As <IDataContext>().InstancePerLifetimeScope(); }
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); }
private static void SetupPatterns(Autofac.ContainerBuilder builder) { var serverModels = (from key in ConfigurationManager.AppSettings.AllKeys where key.StartsWith("ServerAssembly", StringComparison.OrdinalIgnoreCase) select LoadAssembly(ConfigurationManager.AppSettings[key])) .ToList(); if (serverModels.Count == 0) { serverModels = (from asm in NGS.Utility.AssemblyScanner.GetAssemblies() let type = asm.GetType("SystemBoot.Configuration") where type != null && type.GetMethod("Initialize") != null select asm) .ToList(); if (serverModels.Count == 0) { throw new ConfigurationErrorsException(@"Server assemblies not found. When running in compiled mode, server assemblies must be deployed with other assemblies. Alternatively, explicitly specify sever assembly in the config file. Example: <add key=""ServerAssembly_Domain"" value=""AppDomainModel.dll"" />"); } } builder.RegisterGeneratedFactory <NGS.DomainPatterns.DomainModel.Factory>(); builder.RegisterType <NGS.DomainPatterns.DomainModel>(); builder.Register(c => c.Resolve <NGS.DomainPatterns.DomainModel.Factory>()(serverModels)).As <IDomainModel>().SingleInstance(); builder.RegisterType <DomainTypeResolver>().As <ITypeResolver>().SingleInstance(); builder.RegisterType <ServiceLocator>().As <IServiceLocator, IServiceProvider>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(WeakCache <>)).As(typeof(IDataCache <>)).InstancePerLifetimeScope(); builder.RegisterType <DomainEventSource>().As <IDomainEventSource>().InstancePerLifetimeScope(); builder.RegisterType <DomainEventStore>().As <IDomainEventStore>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(SingleDomainEventSource <>)).As(typeof(IDomainEventSource <>)).InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(RegisterChangeNotifications <>)).As(typeof(IObservable <>)).SingleInstance(); builder.RegisterType <DataContext>().As <IDataContext>().InstancePerLifetimeScope(); }
/// <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(); }
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(); }
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 // CAMERA: builder.Register((c, p) => (ICamera)new Camera(p.TypedAs<IPlayer>(), new Vector2(_screenWidth, _screenHeight))).ContainerScoped(); #region Input builder.RegisterModule(new InputModule()); #endregion // Mediator: builder.Register<TweakablePropertiesLoader>().SingletonScoped(); return builder.Build(); }
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(); }