Пример #1
0
        /// <summary>
        /// Initialize the IOC configuration for use with the ServerGame (server logic)
        /// </summary>
        /// <param name="game"></param>
        public static void Initialize(Game game)
        {
            var builder = new ContainerBuilder();

            game.Content.RootDirectory = "Compiled";

            // Monogame
            builder.RegisterInstance(game).SingleInstance();
            builder.RegisterInstance(game.Content).AsSelf();
            builder.RegisterInstance(game.GraphicsDevice).AsSelf();
            builder.RegisterType <Texture2D>();

            // Server logic specific services
            builder.RegisterType <ServerNetworkService>().As <IServerNetworkService>().SingleInstance();
            builder.RegisterType <ServerSettingsService>().As <IServerSettingsService>().SingleInstance();
            builder.RegisterType <ModuleService>().As <IModuleService>()
            .WithParameter("isRunningAsServer", true)
            .SingleInstance();

            builder.RegisterType <ModuleDataService>().As <IModuleDataService>()
            .WithParameter("isRunningAsServer", true)
            .SingleInstance();

            builder.RegisterType <ScreenService>().As <IScreenService>();
            builder.RegisterType <ComponentFactory>().As <IComponentFactory>();

            // Mapping
            builder.RegisterType <ServerObjectMapper>().As <IObjectMapper>().SingleInstance();

            // Screens, Components, and Systems
            IOCHelpers.RegisterScreens(builder);
            IOCHelpers.RegisterComponents(builder);
            IOCHelpers.RegisterSystems(builder);
            builder.RegisterType <ServerSystemLoader>().As <ISystemLoader>().SingleInstance();

            // Entities
            builder.RegisterType <Module>().As <IGameEntity <ModuleData> >();
            builder.RegisterType <Player>().As <IGameEntity <PCData> >();

            // Scripting
            builder.RegisterType <LoggingMethods>().As <ILoggingMethods>().SingleInstance();
            builder.RegisterType <EntityMethods>().As <IEntityMethods>().SingleInstance();
            builder.RegisterType <LocalDataMethods>().As <ILocalDataMethods>().SingleInstance();
            builder.RegisterType <PhysicsMethods>().As <IPhysicsMethods>().SingleInstance();
            builder.RegisterType <ScriptingMethods>().As <IScriptingMethods>().SingleInstance();
            builder.RegisterType <ScriptService>().As <IScriptService>()
            .WithParameter("isServer", true)
            .SingleInstance();

            // Common builds between GUI and server logic
            Initialize(builder);

            _container = builder.Build();
        }
Пример #2
0
        public static void Initialize(Microsoft.Xna.Framework.Game game)
        {
            var builder = new ContainerBuilder();

            game.Content.RootDirectory = "Compiled";

            // Monogame
            builder.RegisterInstance(game);
            builder.RegisterInstance(new SpriteBatch(game.GraphicsDevice)).AsSelf();
            builder.RegisterInstance(game.Content).AsSelf();
            builder.RegisterInstance(game.GraphicsDevice).AsSelf();
            builder.RegisterInstance(new GameSettings());
            builder.RegisterType <Texture2D>();
            builder.RegisterInstance(new Camera2D(game.GraphicsDevice)).AsSelf();

            // Logging
            builder.RegisterType <Logger>().As <ILogger>().SingleInstance();

            // Services
            builder.RegisterType <AppService>().As <IAppService>().SingleInstance();
            builder.RegisterType <DataService>().As <IDataService>().SingleInstance();
            builder.RegisterType <ClientGameService>().As <IGameService>().SingleInstance();
            builder.RegisterType <ScreenService>().As <IScreenService>().SingleInstance();
            builder.RegisterType <GraphicsService>().As <IGraphicsService>().SingleInstance();
            builder.RegisterType <PathService>().As <IPathService>().SingleInstance();
            builder.RegisterType <ClientGameInputService>().As <IInputService>().SingleInstance();
            builder.RegisterType <EngineService>().As <IEngineService>().SingleInstance();
            builder.RegisterType <UIService>().As <IUIService>().SingleInstance();
            builder.RegisterType <ClientNetworkService>().As <IClientNetworkService>().SingleInstance();
            builder.RegisterType <IsoMathService>().As <IIsoMathService>().SingleInstance();
            builder.RegisterType <UserProfile>().As <IUserProfile>().SingleInstance();

            // Artemis
            builder.RegisterType <EntityWorld>().SingleInstance();

            // Factory
            builder.RegisterType <EntityFactory>().As <IEntityFactory>().SingleInstance();
            builder.RegisterType <ComponentFactory>().As <IComponentFactory>().SingleInstance();
            builder.RegisterType <ScreenFactory>().As <IScreenFactory>();
            builder.RegisterType <UIViewModelFactory>().As <IUIViewModelFactory>();

            // Scripting
            builder.RegisterType <LoggingMethods>().As <ILoggingMethods>().SingleInstance();
            builder.RegisterType <EntityMethods>().As <IEntityMethods>().SingleInstance();
            builder.RegisterType <LocalDataMethods>().As <ILocalDataMethods>().SingleInstance();
            builder.RegisterType <PhysicsMethods>().As <IPhysicsMethods>().SingleInstance();
            builder.RegisterType <ScriptingMethods>().As <IScriptingMethods>().SingleInstance();
            builder.RegisterType <ScriptService>().As <IScriptService>()
            .WithParameter("isServer", false)
            .SingleInstance();

            // Game components
            RegisterGameEntities(builder);
            RegisterUIViewModels(builder);
            IOCHelpers.RegisterComponents(builder);
            IOCHelpers.RegisterSystems(builder);
            IOCHelpers.RegisterScreens(builder);


            _container = builder.Build();
        }
Пример #3
0
        public static void Initialize(ContainerBuilder builder)
        {
            // Logging
            builder.RegisterType <Logger>().As <ILogger>().SingleInstance();

            // Artemis
            builder.RegisterType <EntityWorld>().SingleInstance();
            IOCHelpers.RegisterSystems(builder);
            builder.RegisterType <ToolsetSystemLoader>().As <ISystemLoader>().SingleInstance();

            // Services
            builder.RegisterType <AppService>().As <IAppService>().SingleInstance();
            builder.RegisterType <DataService>().As <IDataService>().SingleInstance();
            builder.RegisterType <ToolsetGameService>().As <IGameService>().SingleInstance();
            builder.RegisterType <ScreenService>().As <IScreenService>().SingleInstance();
            builder.RegisterType <GraphicsService>().As <IGraphicsService>().SingleInstance();
            builder.RegisterType <PathService>().As <IPathService>().SingleInstance();
            builder.RegisterType <ToolsetInputService>().As <IInputService>().SingleInstance();
            builder.RegisterType <ModuleDataService>().As <IModuleDataService>()
            .WithParameter("isRunningAsServer", false)
            .SingleInstance();
            builder.RegisterType <ModuleResourceService>().As <IModuleResourceService>();
            builder.RegisterType <ModuleService>().As <IModuleService>()
            .WithParameter("isRunningAsServer", false)
            .SingleInstance();
            builder.RegisterType <EngineService>().As <IEngineService>().SingleInstance();
            builder.RegisterType <IsoMathService>().As <IIsoMathService>().SingleInstance();

            // Factory
            builder.RegisterType <EntityFactory>().As <IEntityFactory>().SingleInstance();
            builder.RegisterType <ComponentFactory>().As <IComponentFactory>().SingleInstance();
            builder.RegisterType <ScreenFactory>().As <IScreenFactory>();
            builder.RegisterType <ObservableDataFactory>().As <IObservableDataFactory>();

            // Scripting
            builder.RegisterType <LoggingMethods>().As <ILoggingMethods>().SingleInstance();
            builder.RegisterType <EntityMethods>().As <IEntityMethods>().SingleInstance();
            builder.RegisterType <LocalDataMethods>().As <ILocalDataMethods>().SingleInstance();
            builder.RegisterType <PhysicsMethods>().As <IPhysicsMethods>().SingleInstance();
            builder.RegisterType <ScriptingMethods>().As <IScriptingMethods>().SingleInstance();

            // Mapping
            builder.RegisterType <ToolsetObjectMapper>().As <IObjectMapper>();

            // Domain Services
            builder.RegisterType <DomainServiceNotifier>().As <IDomainServiceNotifier>().SingleInstance();
            builder.RegisterType <DataEditorDomainService>().As <IDataEditorDomainService>();
            builder.RegisterType <ResourceEditorDomainService>().As <IResourceEditorDomainService>();
            builder.RegisterType <DataDomainService>().As <IDataDomainService>().SingleInstance();

            // Validation
            builder.RegisterType <ValidationHelper>().As <IValidationHelper>();

            // Game components
            IOCHelpers.RegisterScreens(builder);
            IOCHelpers.RegisterComponents(builder);

            // Entities
            builder.RegisterType <Area>().As <IGameEntity <AreaData> >();
            builder.RegisterType <ObjectPainter>().As <IGameEntity <Texture2D> >();

            // MonoGame
            RegisterMonogame(builder);
        }