示例#1
0
 public Startup(IConfiguration configuration)
 {
     Configuration = configuration;
     CorsOrigins   = configuration["App:CorsOrigins"]
                     .Split(",", StringSplitOptions.RemoveEmptyEntries)
                     .ToArray();
     BsonMapping.MapModels();
 }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services
            .AddMvc(options =>
            {
                // Disable automatic fallback to JSON
                options.ReturnHttpNotAcceptable = true;

                // Honor browser's Accept header (e.g. Chrome)
                options.RespectBrowserAcceptHeader = true;
            })
            .AddXmlDataContractSerializerFormatters()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // Add application specific services
            services
            // Register MongoDatabase instance
            .AddMongoDatabase(
                () => Configuration.GetConnectionString("DefaultConnection"),
                "library_database",
                () => BsonMapping.Configure())
            .AddScoped <IBookRepository, BookRepository>();
        }