Exemplo n.º 1
0
        public static IServiceCollection AddAnalyticsServices(
            this IServiceCollection services,
            IConfiguration configuration,
            ILogger logger,
            NetherServiceSwitchSettings serviceSwitches,
            IHostingEnvironment hostingEnvironment
            )
        {
            bool enabled = configuration.GetValue <bool>("Analytics:Enabled");

            if (!enabled)
            {
                logger.LogInformation("Analytics service not enabled");
                return(services);
            }
            logger.LogInformation("Configuring Analytics service");
            serviceSwitches.AddServiceSwitch("Analytics", true);


            services.AddEndpointInfo(configuration, logger, "Analytics:EventHub");
            services.AddServiceFromConfiguration("Analytics:Store", s_wellKnownStoreTypes, configuration, logger, hostingEnvironment);


            return(services);
        }
        public static IServiceCollection AddLeaderboardServices(
            this IServiceCollection services,
            IConfiguration configuration,
            ILogger logger,
            NetherServiceSwitchSettings serviceSwitches,
            IHostingEnvironment hostingEnvironment
            )
        {
            bool enabled = configuration.GetValue <bool>("Leaderboard:Enabled");

            if (!enabled)
            {
                logger.LogInformation("Leaderboard service not enabled");
                return(services);
            }
            logger.LogInformation("Configuring Leaderboard service");
            serviceSwitches.AddServiceSwitch("Leaderboard", true);

            services.AddServiceFromConfiguration("Leaderboard:Store", s_wellKnownStoreTypes, configuration, logger, hostingEnvironment);

            AddLeaderboardProvider(services, configuration);

            services.AddServiceFromConfiguration("Leaderboard:AnalyticsIntegrationClient", s_wellKnownAnalyticsIntegrationTypes, configuration, logger, hostingEnvironment);
            services.AddServiceFromConfiguration("Leaderboard:PlayerManagementClient", s_wellKnownPlayerManagementClientTypes, configuration, logger, hostingEnvironment);

            return(services);
        }
Exemplo n.º 3
0
        public static IServiceCollection AddPlayerManagementServices(
            this IServiceCollection services,
            IConfiguration configuration,
            ILogger logger,
            NetherServiceSwitchSettings serviceSwitches,
            IHostingEnvironment hostingEnvironment
            )
        {
            bool enabled = configuration.GetValue <bool>("PlayerManagement:Enabled");

            if (!enabled)
            {
                logger.LogInformation("PlayerManagement service not enabled");
                return(services);
            }
            logger.LogInformation("Configuring PlayerManagement service");
            serviceSwitches.AddServiceSwitch("PlayerManagement", true);

            services.AddServiceFromConfiguration("PlayerManagement:Store", s_wellKnownStoreTypes, configuration, logger, hostingEnvironment);

            return(services);
        }
Exemplo n.º 4
0
        public static IServiceCollection AddAnalyticsServices(
            this IServiceCollection services,
            IConfiguration configuration,
            ILogger logger,
            NetherServiceSwitchSettings serviceSwitches
            )
        {
            bool enabled = configuration.GetValue <bool>("Analytics:Enabled");

            if (!enabled)
            {
                logger.LogInformation("Analytics service not enabled");
                return(services);
            }
            logger.LogInformation("Configuring Analytics service");
            serviceSwitches.AddServiceSwitch("Analytics", true);


            services.AddEndpointInfo(configuration, logger, "Analytics:EventHub");
            ConfigureAnalyticsStore(services, configuration, logger);

            return(services);
        }
        public static IServiceCollection AddLeaderboardServices(
            this IServiceCollection services,
            IConfiguration configuration,
            ILogger logger,
            NetherServiceSwitchSettings serviceSwitches
            )
        {
            bool enabled = configuration.GetValue <bool>("Leaderboard:Enabled");

            if (!enabled)
            {
                logger.LogInformation("Leaderboard service not enabled");
                return(services);
            }
            logger.LogInformation("Configuring Leaderboard service");
            serviceSwitches.AddServiceSwitch("Leaderboard", true);

            AddLeaderboardStore(services, configuration, logger);

            AddAnalyticsIntegrationClient(services, configuration, logger);

            return(services);
        }
Exemplo n.º 6
0
        public static IServiceCollection AddIdentityServices(
            this IServiceCollection services,
            IConfiguration configuration,
            ILogger logger,
            NetherServiceSwitchSettings serviceSwitches,
            IHostingEnvironment hostingEnvironment)
        {
            bool enabled = configuration.GetValue <bool>("Identity:Enabled");

            if (!enabled)
            {
                logger.LogInformation("Identity service not enabled");
                return(services);
            }
            logger.LogInformation("Configuring Identity service");
            serviceSwitches.AddServiceSwitch("Identity", true);
            serviceSwitches.AddServiceSwitch("IdentityUi", true);

            ConfigureIdentityPlayerMangementClient(services, configuration, logger);
            ConfigureIdentityServer(services, configuration, logger, hostingEnvironment);
            ConfigureIdentityStore(services, configuration, logger);

            return(services);
        }
Exemplo n.º 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IConfiguration>(Configuration);
            services.AddApplicationPerformanceMonitoring(Configuration, _logger, _hostingEnvironment);

            // Initialize switches for nether services
            var serviceSwitches = new NetherServiceSwitchSettings();

            services.AddSingleton(serviceSwitches);

            services.AddOptions();
            services.Configure <SignInMethodOptions>(Configuration.GetSection("Identity:SignInMethods"));

            // Add framework services.
            services
            .AddMvc(options =>
            {
                options.Conventions.Add(new FeatureConvention());
                options.Filters.AddService(typeof(ExceptionLoggingFilterAttribute));
                options.InputFormatters.Add(new PlainTextInputFormatter());
            })
            .ConfigureApplicationPartManager(partManager =>
            {
                // swap out the default ControllerFeatureProvider for ours which filters based on the nether service switches
                var defaultProvider = partManager.FeatureProviders.FirstOrDefault(p => p is ControllerFeatureProvider);
                if (defaultProvider != null)
                {
                    partManager.FeatureProviders.Remove(defaultProvider);
                }
                partManager.FeatureProviders.Add(new NetherServiceControllerFeatureProvider(serviceSwitches));
            })
            .AddRazorOptions(options =>
            {
                // {0} - Action Name
                // {1} - Controller Name
                // {2} - Area Name
                // {3} - Feature Name
                options.AreaViewLocationFormats.Clear();
                options.AreaViewLocationFormats.Add("/Areas/{2}/Features/{3}/Views/{1}/{0}.cshtml");
                options.AreaViewLocationFormats.Add("/Areas/{2}/Features/{3}/Views/{0}.cshtml");
                options.AreaViewLocationFormats.Add("/Areas/{2}/Features/Views/Shared/{0}.cshtml");
                options.AreaViewLocationFormats.Add("/Areas/Shared/{0}.cshtml");

                // replace normal view location entirely
                options.ViewLocationFormats.Clear();
                options.ViewLocationFormats.Add("/Features/{3}/Views/{1}/{0}.cshtml");
                options.ViewLocationFormats.Add("/Features/{3}/Views/Shared/{0}.cshtml");
                options.ViewLocationFormats.Add("/Features/{3}/Views/{0}.cshtml");
                options.ViewLocationFormats.Add("/Features/Views/Shared/{0}.cshtml");

                options.ViewLocationExpanders.Add(new FeatureViewLocationExpander());
            })
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.Converters.Add(new StringEnumConverter
                {
                    CamelCaseText = true
                });
            });

            services.AddCors();

            services.ConfigureSwaggerGen(options =>
            {
                string commentsPath = Path.Combine(
                    PlatformServices.Default.Application.ApplicationBasePath,
                    "Nether.Web.xml");

                options.IncludeXmlComments(commentsPath);
            });

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v0.1", new Info
                {
                    Version = "v0.1",
                    Title   = "Project Nether",
                    License = new License
                    {
                        Name = "MIT",
                        Url  = "https://github.com/MicrosoftDX/nether/blob/master/LICENSE"
                    }
                });
                options.CustomSchemaIds(type => type.FullName);
                options.AddSecurityDefinition("oauth2", new OAuth2Scheme
                {
                    Type             = "oauth2",
                    Flow             = "implicit",
                    AuthorizationUrl = "/identity/connect/authorize",
                    Scopes           = new Dictionary <string, string>
                    {
                        { "nether-all", "nether API access" },
                    }
                });

                options.OperationFilter <SecurityRequirementsOperationFilter>();
            });

            services.AddSingleton <ExceptionLoggingFilterAttribute>();


            services.AddIdentityServices(Configuration, _logger, serviceSwitches, _hostingEnvironment);
            services.AddLeaderboardServices(Configuration, _logger, serviceSwitches, _hostingEnvironment);
            services.AddPlayerManagementServices(Configuration, _logger, serviceSwitches, _hostingEnvironment);
            services.AddAnalyticsServices(Configuration, _logger, serviceSwitches, _hostingEnvironment);


            services.AddAuthorization(options =>
            {
                options.AddPolicy(
                    PolicyName.NetherIdentityClientId,
                    policy => policy.RequireClaim(
                        "client_id",
                        "nether_identity"
                        ));
            });
        }
        public static IServiceCollection AddPlayerManagementServices(
            this IServiceCollection services,
            IConfiguration configuration,
            ILogger logger,
            NetherServiceSwitchSettings serviceSwitches
            )
        {
            bool enabled = configuration.GetValue <bool>("PlayerManagement:Enabled");

            if (!enabled)
            {
                logger.LogInformation("PlayerManagement service not enabled");
                return(services);
            }
            logger.LogInformation("Configuring PlayerManagement service");
            serviceSwitches.AddServiceSwitch("PlayerManagement", true);

            // TODO - look at what can be extracted to generalise this
            if (configuration.Exists("PlayerManagement:Store:wellKnown"))
            {
                // register using well-known type
                var    wellKnownType       = configuration["PlayerManagement:Store:wellknown"];
                var    scopedConfiguration = configuration.GetSection("PlayerManagement:Store:properties");
                string connectionString    = scopedConfiguration["ConnectionString"];
                switch (wellKnownType)
                {
                case "mongo":
                    logger.LogInformation("PlayerManagement:Store: using 'mongo' store");
                    string databaseName = scopedConfiguration["DatabaseName"];

                    services.AddTransient <IPlayerManagementStore>(serviceProvider =>
                    {
                        var storeLogger = serviceProvider.GetRequiredService <ILogger <MongoDBPlayerManagementStore> >();
                        // TODO - look at encapsulating the connection info and registering that so that we can just register the type without the factory
                        return(new MongoDBPlayerManagementStore(connectionString, databaseName, storeLogger));
                    });
                    break;

                case "in-memory":
                    logger.LogInformation("PlayerManagement:Store: using 'in-memory' store");
                    services.AddTransient <PlayerManagementContextBase, InMemoryPlayerManagementContext>();
                    services.AddTransient <IPlayerManagementStore, EntityFrameworkPlayerManagementStore>();
                    break;

                case "sql":
                    logger.LogInformation("PlayerManagement:Store: using 'sql' store");
                    services.AddSingleton(new SqlPlayerManagementContextOptions {
                        ConnectionString = connectionString
                    });
                    services.AddTransient <PlayerManagementContextBase, SqlPlayerManagementContext>();
                    services.AddTransient <IPlayerManagementStore, EntityFrameworkPlayerManagementStore>();
                    break;

                default:
                    throw new Exception($"Unhandled 'wellKnown' type for PlayerManagement:Store: '{wellKnownType}'");
                }
            }
            else
            {
                // fall back to generic "factory"/"implementation" configuration
                services.AddServiceFromConfiguration <IPlayerManagementStore>(configuration, logger, "PlayerManagement:Store");
            }
            return(services);
        }