Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 public void SetUp()
 {
     timer = new Timer();
 }