// 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(); }
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(); }
public void CreatePet(string type, string name, DateTime birthday, DateTime soldDate, string colour, string previousOwner, double price) { Pet pet1 = new Pet() { Name = name, Type = type, Birthday = birthday, SoldDate = soldDate, Colour = colour, PreviousOwner = previousOwner, Price = price, }; FakePetDatabase.InsertInto(pet1); }
public void DeletePet(int id) { Pet petToDelete = null; foreach (Pet p in GetPets()) { if (p.ID == id) { petToDelete = p; } } if (petToDelete != null) { FakePetDatabase.DeletePet(petToDelete.ID); } }
public IEnumerable <Pet> GetPets() { return(FakePetDatabase.SelectAll()); }