public MongoDbContext() { _mongoDbRunner = MongoDbRunner.Start(); MongoClient = new MongoClient(_mongoDbRunner.ConnectionString); MongoDatabase = MongoClient.GetDatabase("db"); MongoMap.RegisterClasses(); var coll = MongoDatabase.GetCollection <User>("users"); coll.InsertOne(new User("admin")); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { MongoMap.Configure(); services.Configure <NinjaDatabaseSettings>(Configuration.GetSection("NinjaDatabaseSettings")); services.Configure <ProductSettings>(Configuration.GetSection("ProductService")); services.Configure <OrderSettings>(Configuration.GetSection("OrderService")); services.AddControllers(); services.AddSingleton <ILoggin, Loggin>(); services.AddSingleton <IUnitOfWork, UnitOfWork>(); services.AddHttpClient(); services.AddSingleton <IProductService, ProductService>(); services.AddSingleton <IOrderService, OrderService>(); services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ValidatorPipelineBehavior <,>)); services.AddMediatR(typeof(GetAllUsersQuery)); services.AddSwaggerGen( config => config.SwaggerDoc( "NinjaAPI", new Microsoft.OpenApi.Models.OpenApiInfo() { Title = "Controllers Info" }) ); string basePath = hostingEnvironment.ContentRootPath; services.AddSwaggerGen( config => config.IncludeXmlComments(Path.Combine(basePath, "Ninja.Api.xml")) ); services.AddValidatorsFromAssembly(typeof(AddUserCommandValidator).Assembly); }