Beispiel #1
0
        public static void ResolveDependencies()
        {
            Container = BuildContainer();
            Container.Resolve <ReverseGeoCodingService>();
            Container.Resolve <IBusControl>();
            Container.Resolve <IRedisCache>();
            Container.Resolve <ILogger>();

            var path = Directory.GetCurrentDirectory();

            MicroServicesLoader.Loader(path);
        }
Beispiel #2
0
        protected void Application_Start()
        {
            #region add masstransit consumer

            try
            {
                RabbitMqConfig
                .InitReceiverBus <SignalRHandler>("Smartfleet.Web.endpoint")
                .StartAsync()
                .GetAwaiter();
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                //throw;
            }
            #endregion

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            BundleTable.EnableOptimizations = false;
            // seed user administrator and roles
            SeedInitialData();

            #region register different services and classes using autofac
#if DEBUG
            TelemetryConfiguration.Active.DisableTelemetry = true;
#endif
            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterAssemblyTypes(typeof(MvcApplication).Assembly)
            .AsImplementedInterfaces();

            builder.RegisterModule(new AutofacWebTypesModule());
            //builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterType <SmartFleetObjectContext>().As <SmartFleetObjectContext>();

            builder.RegisterType <UserStore <IdentityUser> >().As <IUserStore <IdentityUser> >();
            builder.RegisterType <RoleStore <IdentityRole> >().As <IRoleStore <IdentityRole, string> >();
            builder.RegisterType <UserManager <IdentityUser> >();
            builder.RegisterType <AuthenticationService>().As <IAuthenticationService>();
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterType <DbContextScopeFactory>().As <IDbContextScopeFactory>();
            builder.RegisterType <ReverseGeoCodingService>().As <ReverseGeoCodingService>();
            builder.RegisterType <VehicleService>().As <IVehicleService>();
            builder.RegisterType <CustomerService>().As <ICustomerService>();

            builder.RegisterType <PositionService>().As <IPositionService>();
            builder.RegisterType <CustomerService>().As <ICustomerService>();
            builder.RegisterType <PdfService>().As <IPdfService>();
            #endregion

            #region automapper

            var mapperConfiguration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new SmartFleetAdminMappings());
            });
            var mapper = mapperConfiguration.CreateMapper();
            builder.RegisterInstance(mapper).As <IMapper>();
            SignalRHubManager.Mapper = mapper;
            var queryBuilder = new DataTablesLinqQueryBulider();
            builder.RegisterInstance(queryBuilder).As <DataTablesLinqQueryBulider>();
            #endregion

            var container = builder.Build();
            var path      = Server.MapPath("/") + @"bin\microservices";
            MicroServicesLoader.Loader(path);

            //    container.Resolve<IAmbientDbContextLocator>();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            // GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver((IContainer)container);
        }