Example #1
0
        public virtual HttpConfiguration GetInjectionConfiguration()
        {
            var configuration = new HttpConfiguration();
            var container     = new UnityContainer();

            var config  = new EwebahConfig();
            var context = new CarShareContext(config);
            var mailer  = new WelcomeMailer(config.SmtpUsername, config.SmtpPassword, config.SmtpServer,
                                            config.SmtpPort);

            container.RegisterInstance <IEmailProvider>(mailer);

            //specify concrete instances of classes that should be injected when interface is marked
            container.RegisterType <IUserRepository, UserRepository>(new TransientLifetimeManager(),
                                                                     new InjectionConstructor(context));
            container.RegisterType <IBookingRepository, BookingRepository>(new TransientLifetimeManager(),
                                                                           new InjectionConstructor(context));
            container.RegisterType <IRegistrationRepository, RegistrationRepository>(new TransientLifetimeManager(),
                                                                                     new InjectionConstructor(context));
            container.RegisterType <ICarRepository, CarRepository>(new TransientLifetimeManager(),
                                                                   new InjectionConstructor(context));
            container.RegisterType <ICarCategoryRepository, CarCategoryRepository>(new TransientLifetimeManager(),
                                                                                   new InjectionConstructor(context));
            container.RegisterType <ICityRepository, CityRepository>(new TransientLifetimeManager(),
                                                                     new InjectionConstructor(context));
            container.RegisterType <ITransactionHistoryRepository, TransactionHistoryRepository>(
                new TransientLifetimeManager(), new InjectionConstructor(context));
            container.RegisterType <IPaymentMethodRepository, PaymentMethodRepository>(new TransientLifetimeManager(),
                                                                                       new InjectionConstructor(context));
            container.RegisterType <ITemplateRepository, TemplateRepository>(new TransientLifetimeManager(),
                                                                             new InjectionConstructor(context));

            container.RegisterType <IUserService, UserService>(new TransientLifetimeManager());
            container.RegisterType <ICarService, CarService>(new TransientLifetimeManager());
            container.RegisterType <IBookingService, BookingService>(new TransientLifetimeManager());
            container.RegisterType <ICityService, CityService>(new TransientLifetimeManager());
            container.RegisterType <IAdminService, AdminService>(new TransientLifetimeManager());


            //set this container as the http configurations dependency injection provider
            configuration.DependencyResolver = new UnityResolver(container);
            return(configuration);
        }
Example #2
0
 //This class inherits the IcityRepository register
 public CityRepository(CarShareContext context)
 {
     //Inherits the DB context
     Context = context;
 }
 //This class inherits the IpaymentmethodRepository register
 public PaymentMethodRepository(CarShareContext context)
 {
     //Inherits the DB context
     Context = context;
 }
Example #4
0
 //This class inherits the ItemplateRepository register
 public TemplateRepository(CarShareContext context)
 {
     //Inherits the DB context
     Context = context;
 }
 //This class inherits the IBookingRepository register
 public BookingRepository(CarShareContext context)
 {
     //Inherits the DB context
     Context = context;
 }
 //This class inherits the IregistrationRepository register
 public RegistrationRepository(CarShareContext context)
 {
     //Inherits the DB context
     Context = context;
 }
 //This class inherits the ITransactionHistoryRepository register
 public TransactionHistoryRepository(CarShareContext context)
 {
     //Inherits the DB context
     Context = context;
 }