Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();


            // Configure XPO Data Store Service
            string           connectionString;
            AutoCreateOption autoCreateOption = AutoCreateOption.SchemaAlreadyExists;

            if (HostingEnvironment.IsDevelopment())
            {
                connectionString = Configuration.GetConnectionString("Dev");
                autoCreateOption = AutoCreateOption.DatabaseAndSchema;
            }
            else
            {
                connectionString = Configuration.GetConnectionString("Prod");
                connectionString = XpoDefault.GetConnectionPoolString(connectionString);
            }
            IDataStore             dataStore = XpoDefault.GetConnectionProvider(connectionString, autoCreateOption);
            WebApiDataStoreService service   = new WebApiDataStoreService(dataStore);

            services.AddSingleton(dataStore);
            services.AddSingleton(service);

            services.AddMvc().AddXmlSerializerFormatters();
            services.AddCors(options =>
                             options.AddPolicy("XPO", builder =>
                                               builder.WithOrigins("https://localhost:44317")
                                               .WithMethods("POST")
                                               .WithHeaders("Content-Type")));
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddSwaggerGen(c => {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "icden.NetCore.API", Version = "v1"
                });
            });

            string connStrName      = "Futurecom";
            string connectionString = Configuration.GetConnectionString(connStrName);

            //Initialize XPODataLayer / Database
            services.AddXpoDatabase((o) => {
                o.Name             = connStrName;
                o.ConnectionString = connectionString;
            });
            //Initialize identity to use XPO
            services
            .AddIdentity <ApplicationUser, ApplicationRole>(options => {
                // Password settings.
                options.Password.RequireDigit           = true;
                options.Password.RequireLowercase       = true;
                options.Password.RequireNonAlphanumeric = true;
                options.Password.RequireUppercase       = true;
                options.Password.RequiredLength         = 6;
                options.Password.RequiredUniqueChars    = 1;

                // Lockout settings.
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(5);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings.
                options.User.AllowedUserNameCharacters =
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
                options.User.RequireUniqueEmail = false;
            })
            .AddXpoIdentityStores <ApplicationUser, XpoApplicationUser, ApplicationRole, XpoApplicationRole>(connStrName,
                                                                                                             new ApplicationUserMapper(),
                                                                                                             new ApplicationRoleMapper(),
                                                                                                             new XPUserStoreValidator <string, ApplicationUser, XpoApplicationUser>(),
                                                                                                             new XPRoleStoreValidator <string, ApplicationRole, XpoApplicationRole>())
            .AddDefaultTokenProviders();

            IDataStore             dataStore = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);
            WebApiDataStoreService service   = new WebApiDataStoreService(dataStore);

            services.AddSingleton(service);

            services.AddMvc().AddXmlSerializerFormatters();

            services.AddCors(options =>
                             options.AddPolicy("XPO", builder =>
                                               builder.AllowAnyOrigin()
                                               .WithMethods("POST")
                                               .WithHeaders("Content-Type")));
        }
Beispiel #3
0
 public XpoController(WebApiDataStoreService dataStoreService)
 {
     this.DataStoreService = dataStoreService;
 }