static void Main(string[] args) { var serviceCollection = new ServiceCollection(); serviceCollection.AddScoped <IAvatarRepository, AvatarRepo>(); serviceCollection.AddScoped <IAvatarService, AvatarService>(); serviceCollection.AddScoped <IPrinter, Printer>(); var serviceProvider = serviceCollection.BuildServiceProvider(); var avatarRepo = serviceProvider.GetRequiredService <IAvatarRepository>(); var Printer = serviceProvider.GetRequiredService <IPrinter>(); new DBInit(avatarRepo).InitData(); IAvatarRepository aRepo = new AvatarRepo(); DBInit db = new DBInit(aRepo); db.InitData(); // Mock data IAvatarService aService = new AvatarService(aRepo); IPrinter print = new Printer(aService); Console.WriteLine("Hello fellow Seven Deadly Sins maniac!"); Console.WriteLine("Welcome to SDS\nBegin your adventure by choosing an option in the menu"); print.StartUI(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseSwagger(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } using (var scope = app.ApplicationServices.CreateScope()) { var repo = scope.ServiceProvider.GetRequiredService <IAvatarRepository>(); var orepo = scope.ServiceProvider.GetRequiredService <IOwnerRepository>(); var trepo = scope.ServiceProvider.GetRequiredService <ITypeRepository>(); /* repo.Create(new Avatar { Name = "Chili", AvatarType = "Magician", Color = "Pink" }); * repo.Create(new Avatar { Name = "Bunsy", AvatarType = "Healer", Color = "Black" });*/ IAvatarRepository aRepo = new AvatarRepo(); IOwnerRepository owRepo = new OwnerRepo(); ITypeRepository tyrepo = new TypeRepo(); DBInit.InitData(); // Mock data IAvatarService aService = new AvatarService(aRepo); IOwnerService owService = new OwnerService(owRepo); ITypeService tService = new TypeService(tyrepo); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); // c.RoutePrefix = string.Empty; }); app.UseHttpsRedirection(); app.UseRouting(); app.UseCors("CustomerAppAllowSpecificOrigins"); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } }