Ejemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            FluentValidationModelValidatorProvider.Configure();
            IUnityContainer container = new UnityContainer();

            UnityRegistrar.Register(container);

            AutoMapperInitializer.Initialise();

            ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory(container));
            DummyDataCreator.PopulateRepository();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers the type mappings with the Unity container.
        /// </summary>
        /// <param name="unityContainer">The unity container to configure.</param>
        /// <remarks>
        /// There is no need to register concrete types such as controllers or
        /// API controllers (unless you want to change the defaults), as Unity
        /// allows resolving a concrete type even if it was not previously
        /// registered.
        /// </remarks>
        public static void RegisterTypes(IUnityContainer unityContainer)
        {
            LogManager.GetLogger(typeof(UnityConfig).FullName).Info("Registering components...");


            var di = new UnityRegistrar(unityContainer);

            di.ConnectToServiceLocator();

            RegisterDbContexts(di);

            RegisterHealthMonitors(di);

            // One instance of my Controllers
            //di.RegisterAsSingleInstance<IExampleService>(() => new ExampleService());
            di.RegisterAsSingleInstance <IHotelService>(() => new HotelService());
            di.RegisterAsSingleInstance <ICustomerService>(() => new CustomerService());
            di.RegisterAsSingleInstance <IRoomService>(() => new RoomService());
            di.RegisterAsSingleInstance <IReservationService>(() => new ReservationService());
        }
Ejemplo n.º 3
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure the Dependency Resolver
            var registrar = new UnityRegistrar();
            var container = new UnityContainer();

            container = registrar.Register(container);
            config.DependencyResolver = new UnityResolver(container);

            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }