示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddScoped <IPetRepository, PetRepository>();
            services.AddScoped <IPetService, PetService>();
            services.AddScoped <IOwnerRepository, OwnerRepository>();
            services.AddScoped <IOwnerService, OwnerService>();

            services.AddDbContext <PetshopContext>(
                opt => opt.UseSqlite("Data source=Petshop.db"));

            FakeDb.InitData();
        }
示例#2
0
        static void Main()
        {
            FakeDb.InitData();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <IPetShopRepository, PetShopRepository>();
            serviceCollection.AddScoped <IPetShopService, PetShopService>();
            serviceCollection.AddScoped <IPrinter, Printer>();

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var printer         = serviceProvider.GetRequiredService <IPrinter>();

            printer.ChooseMenuItem();
        }
示例#3
0
        private static void Main()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <IPetRepository, PetRepository>();
            serviceCollection.AddScoped <IPetService, PetService>();
            serviceCollection.AddScoped <IPrinter, Printer>();



            //then build provider
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var printer         = serviceProvider.GetRequiredService <IPrinter>();

            FakeDb.InitData();
            printer.BeginUI();
        }
        static void Main(string[] args)
        {
            //PetPrinter petPrinter = new PetPrinter();

            FakeDb.InitData();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <IPetRepository, PetRepository>();
            serviceCollection.AddScoped <IPrinter, PetPrinter>();
            serviceCollection.AddScoped <IPetService, PetService>();
            serviceCollection.AddScoped <IOwnerService, OwnerService>();
            serviceCollection.AddScoped <IOwnerRepository, OwnerRepository>();

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var petPrinter      = serviceProvider.GetRequiredService <IPrinter>();

            petPrinter.MakeMenu();

            Console.ReadLine();
        }
示例#5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //FakeDB.InitData();
                using (var scope = app.ApplicationServices.CreateScope())
                {
                    var repo = scope.ServiceProvider.GetService <IPetRepository>();
                    FakeDb.InitData();
                }
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }