public static void Main(string[] args) { var containerBuilder = new ContainerBuilder(); containerBuilder .RegisterGeneric(typeof(Repository <>)) .As(typeof(IRepository <>)) .SingleInstance(); containerBuilder .RegisterType <BikeNameVerifier>() .As <IBikeNameVerifier>(); containerBuilder .RegisterType <BikeService>() .As <IBikeService>(); containerBuilder .RegisterType <DepositCalculator>() .As <IDepositCalculator>(); containerBuilder .RegisterType <RentService>() .As <IRentService>(); containerBuilder .RegisterType <DepositService>() .As <IDepositService>(); // ---------------- Command ----------------------- containerBuilder .RegisterType <AddNewBikeCommand>() .As <ICommand <AddNewBikeCommandContext> >(); containerBuilder .RegisterType <AddNewRentPointCommand>() .As <ICommand <AddNewRentPointCommandContext> >(); containerBuilder .RegisterType <AddBikeToRentPointCommand>() .As <ICommand <AddBikeToRentPointCommandContext> >(); containerBuilder .RegisterType <TakeBikeCommand>() .As <ICommand <TakeBikeCommandContext> >(); containerBuilder .RegisterType <ReturnBikeCommand>() .As <ICommand <ReturnBikeCommandContext> >(); //----------------------Query------------------------ containerBuilder .RegisterType <GetAllRentPoint>() .As <IQuery <GetAllEntitiesCriterion, IEnumerable <RentPoint> > >(); containerBuilder .RegisterType <GetAllBikes>() .As <IQuery <GetAllEntitiesCriterion, IEnumerable <Bike> > >(); containerBuilder .RegisterType <GetAllRents>() .As <IQuery <GetAllEntitiesCriterion, IEnumerable <Rent> > >(); //---------------------------------------------------- containerBuilder .RegisterTypedFactory <ICommandFactory>(); containerBuilder .RegisterTypedFactory <IQueryFactory>(); containerBuilder.RegisterType <App>(); IContainer container = containerBuilder.Build(); App app = container.Resolve <App>(); Employee employee = new Employee("Иванов", "Иван", "Иванович"); Employee employee1 = new Employee("Мазеина", "Надежда", "Николаевна"); // Client client = new Client("Петров", "Петр", "Петрович"); Client client1 = new Client("Петров", "Сергей", "Валерьевич"); app.AddRentPoint(employee, 100); app.AddRentPoint(employee1, 6000); app.AddBike("Кама", 50); app.AddBikeToRentPoint("Кама", employee); app.AddBike("Фишер", 100); app.AddBikeToRentPoint("Фишер", employee); IEnumerable <RentPoint> lr = app.GetAllRentPoint(); // app.MakeResevation("Кама", client); // app.TakeBike("Кама", client, new MoneyDeposit(5000)); //// app.CrushBike("Кама", client); // app.ReturnBike("Кама", employee1); app.TakeBike("Кама", client1, new MoneyDeposit(5000)); IEnumerable <Rent> rr = app.GetAllRents(); app.ReturnBike("Кама", employee); IEnumerable <Bike> br = app.GetAllBikes(); container.Dispose(); }
public static void Main(string[] args) { var containerBuilder = new ContainerBuilder(); containerBuilder .RegisterGeneric(typeof(Repository <>)) .As(typeof(IRepository <>)) .SingleInstance(); containerBuilder .RegisterType <BikeNameVerifier>() .As <IBikeNameVerifier>(); containerBuilder .RegisterType <BikeService>() .As <IBikeService>(); containerBuilder .RegisterType <RentPointService>() .As <IRentPointService>(); containerBuilder .RegisterType <EmployeeService>() .As <IEmployeeService>(); containerBuilder .RegisterType <RentService>() .As <IRentService>(); containerBuilder .RegisterType <DepositCalculator>() .As <IDepositCalculator>(); containerBuilder .RegisterType <RentSumCalculate>() .As <IRentSumCalculate>(); containerBuilder .RegisterType <ReserveService>() .As <IReserveService>(); containerBuilder.RegisterAssemblyTypes(typeof(RentPointCriterion).GetTypeInfo().Assembly).AsClosedTypesOf(typeof(IQuery <,>)); containerBuilder.RegisterGeneric(typeof(QueryFor <>)).As(typeof(IQueryFor <>)); containerBuilder.RegisterTypedFactory <IQueryBuilder>().InstancePerLifetimeScope(); containerBuilder.RegisterTypedFactory <IQueryFactory>().InstancePerLifetimeScope(); containerBuilder.RegisterAssemblyTypes(typeof(AddRentPointCommand).GetTypeInfo().Assembly).AsClosedTypesOf(typeof(ICommand <>)); containerBuilder.RegisterType <CommandBuilder>().As <ICommandBuilder>().InstancePerLifetimeScope(); containerBuilder.RegisterTypedFactory <ICommandFactory>().InstancePerLifetimeScope(); containerBuilder.RegisterType <App>(); IContainer container = containerBuilder.Build(); App app = container.Resolve <App>(); Employee myEmployee = app.CreateEmployee("Nya", "Nyan", "Nyanyan"); RentPoint myRentPoint = app.AddRentPoint("rp1", "adress1", myEmployee); Employee otherEmployee = app.CreateEmployee("otherNya", "otherNyan", "otherNyanyan"); RentPoint otherRentPoint = app.AddRentPoint("rp2", "adress2", otherEmployee); Client client = app.CreateClient("Keke", "Ke", "Kekekeke"); Client clientWhoWantTakeReservedBike = app.CreateClient("aaa", "a", "aaaaa"); Deposit deposit = new MoneyDeposit(5000); app.AddBike("Кама", 50, 4500, myRentPoint); app.AddBike("Rainbow Dash", 50, 5000, myRentPoint); app.AddBike("Rainbow Crash", 60, 4700, myRentPoint); //app.AddBike("Кама", 100, myRentPoint); Bike iChooseThisBike = app.GetBikes().FirstOrDefault(x => x.Name == "Кама"); app.ReserveBike(client, iChooseThisBike, DateTime.UtcNow.AddDays(1)); //app.GetBikeInRent(client, iChooseThisBike, deposit); bool iBrokeBike = true; app.GetBikeInRent(client, iChooseThisBike, deposit); app.ReturnBike(iChooseThisBike, otherRentPoint, iBrokeBike); app.GetRentPoints(); app.GetAllFreeBikesOnRentPoint(myRentPoint); Bike likeItBike = app.GetBikes().FirstOrDefault(x => x.Name == "Rainbow Dash"); app.ReserveBike(client, likeItBike, DateTime.UtcNow.AddDays(1)); app.GetOpenReserveByBike(likeItBike); app.GetBikes(); Console.ReadLine(); container.Dispose(); }
public static void Main(string[] args) { var containerBuilder = new ContainerBuilder(); containerBuilder .RegisterGeneric(typeof(Repository <>)) .As(typeof(IRepository <>)) .SingleInstance(); containerBuilder .RegisterType <BikeNameVerifier>() .As <IBikeNameVerifier>(); containerBuilder .RegisterType <BikeService>() .As <IBikeService>(); containerBuilder .RegisterType <RentPointService>() .As <IRentPointService>(); containerBuilder .RegisterType <EmployeeService>() .As <IEmployeeService>(); containerBuilder .RegisterType <RentService>() .As <IRentService>(); containerBuilder .RegisterType <DepositCalculator>() .As <IDepositCalculator>(); containerBuilder .RegisterType <RentSumCalculate>() .As <IRentSumCalculate>(); containerBuilder.RegisterTypedFactory <ICommandFactory>(); containerBuilder.RegisterTypedFactory <IQueryFactory>(); containerBuilder.RegisterTypedFactory <IQueryBuilder>(); containerBuilder .RegisterGeneric(typeof(QueryFor <>)) .As(typeof(IQueryFor <>)); containerBuilder .RegisterAssemblyTypes(typeof(GetAllRentPointsQuery).GetTypeInfo().Assembly) .AsClosedTypesOf(typeof(IQuery <,>)); containerBuilder .RegisterType <CommandBuilder>() .As <ICommandBuilder>(); containerBuilder .RegisterAssemblyTypes(typeof(AddBikeCommand).GetTypeInfo().Assembly) .AsClosedTypesOf(typeof(ICommand <>)); containerBuilder.RegisterType <App>(); IContainer container = containerBuilder.Build(); App app = container.Resolve <App>(); Employee myEmployee = app.CreateEmployee("Nya", "Nyan", "Nyanyan"); RentPoint rp = app.AddRentPoint("Компрос", myEmployee); Employee otherEmployee = app.CreateEmployee("otherNya", "otherNyan", "otherNyanyan"); app.AddRentPoint("Ленина", otherEmployee); Client client = app.CreateClient("Keke", "Ke", "Kekekeke"); Client clientWhoWantTakeReservedBike = app.CreateClient("aaa", "a", "aaaaa"); Deposit deposit = new MoneyDeposit(5000); app.AddBike("Кама", 50, 4500, rp); app.AddBike("Кама", 100, 4500, rp); //Bike iChooseThisBike = app.GetBikes().FirstOrDefault(x => x.Name == "Кама"); //app.ReserveBike(client, iChooseThisBike, DateTime.UtcNow.AddDays(1)); //app.GetBikeInRent(client, iChooseThisBike, deposit); //bool iBrokeBike = true; //app.GetBikeInRent(client, iChooseThisBike, deposit); //app.ReturnBike(iChooseThisBike, otherRentPoint, iBrokeBike); container.Dispose(); }