Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            // Add cookie authentication and set the login url
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options => { options.LoginPath = "/Auth/Login"; });

            if (File.Exists(SecretsFileName) == false)
            {
                throw new InvalidOperationException("You need to have a secrets file setup");
            }
            var secrets = JsonConvert.DeserializeObject <Secrets>(File.ReadAllText(SecretsFileName));
            // Register your application at: https://developers.eveonline.com/applications to obtain client ID and secret key and add them to user secrets
            // by right-clicking the solution and selecting Manage User Secrets.
            // Also, modify the callback URL in appsettings.json to match with your environment.

            // Initialize the client
            var esiClient = new EVEStandardAPI(
                "EVEAsset.Navigator",     // User agent
                DataSource.Tranquility,   // Server [Tranquility/Singularity]
                TimeSpan.FromSeconds(30), // Timeout
                Configuration["SSOCallbackUrl"],
                secrets.ClientId,
                secrets.SecretKey);

            // Register with DI container
            services.AddSingleton(esiClient);

            // Session is required
            services.AddSession();

            services.AddMemoryCache();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            var tranquilityContext = new TranquilityContext(new DbContextOptions <TranquilityContext>());

            tranquilityContext.ConfigureServices(services, secrets.SdeConnectionString);

            var navigatorContext = new NavigatorContext(new DbContextOptions <NavigatorContext>());

            navigatorContext.ConfigureServices(services, secrets.NavigatorConnectionString);

            services.AddSingleton(typeof(TranquilityContext), tranquilityContext);
            services.AddSingleton(typeof(NavigatorContext), navigatorContext);
            services.AddSingleton <IUniverseCache, UniverseCache>();
            services.AddSingleton <IStaticDataRepository, StaticDataRepository>();
            services.AddSingleton <IJumpCache, JumpCache>();
        }