Exemple #1
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddScoped <IPetRepository, PetRepository>();
     services.AddScoped <IPetService, PetService>();
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
     FakePetDatabase.InitialiseData();
 }
Exemple #2
0
        public static void Main(string[] args)
        {
            ServiceCollection serviceCollection = new ServiceCollection();

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

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

            printer.StartUI();
        }