Exemple #1
0
        public static IContainer Initialize()
        {
            var builder  = new ContainerBuilder();
            var assembly = typeof(Startup).Assembly;

            builder.RegisterApiControllers(assembly);

            builder.RegisterType <ApplicationDbContext>().As <IAppContext>();
            builder.RegisterType <AppConfig>().As <IAppConfig>();
            builder.RegisterType <CacheService>().As <ICacheService>();
            builder.RegisterType <JsonConfigSerializer>().As <IConfigSerializer>();
            builder.RegisterType <DefaultServiceSettings>().As <IServiceSettings>();
            builder.RegisterType <ApplicationOAuthProvider>().AsSelf().SingleInstance();

            builder.RegisterInstance(LogManager.GetLogger(typeof(Startup))).As <ILog>();

            //Mapper dependencies
            builder.RegisterGeneric(typeof(PagedListConverter <,>));

            // Global items registrations
            MapperRegistration.Register(builder);

            //// Register class by Name convention
            builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()).Where(x => x.Name.EndsWith("Service")).AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(assembly)
            .Where(x => x.Name.EndsWith("Repository"))
            .InstancePerRequest();

            return(builder.Build());
        }
Exemple #2
0
        public static void Run()
        {
            // Configure Autofac
            AutofacWebapiConfig.Initialize(GlobalConfiguration.Configuration);

            //Configure AutoMapper
            MapperRegistration.RegisterMapperConfiguration();
        }
Exemple #3
0
        public void ItShouldCorrectlyConfigured()
        {
            // arrange
            var config = MapperRegistration.GetMapperConfiguration();

            // act

            // assert
            config.AssertConfigurationIsValid();
        }
Exemple #4
0
        public void Configuration(IAppBuilder app)
        {
            // Configure Autofac
            _container = ConfigureAutofac(_config, app);

            // Configure automapper
            MapperRegistration.RegisterMapperConfiguration();

            // Configure CORS
            ConfigureCors(app);

            // Configure Web Api
            ConfigureWebAPIRouting(_config);
        }
Exemple #5
0
        public static void Initialize()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterAssemblyTypes(typeof(MvcApplication).Assembly).AsImplementedInterfaces();
            builder.RegisterSource(new ViewRegistrationSource());
            builder.RegisterModule(new AutofacWebTypesModule());
            builder.RegisterFilterProvider();

            builder.RegisterType <ApplicationDbContext>().As <IContext>().InstancePerRequest();

            builder.RegisterType <EditablePageRepository>().AsSelf();
            builder.RegisterType <AppConfig>().As <IAppConfig>().InstancePerRequest();
            builder.RegisterType <CacheService>().As <ICacheService>().InstancePerRequest();

            builder.RegisterType <JsonConfigSerializer>().As <IConfigSerializer>().InstancePerRequest();
            builder.RegisterType <CacheService>().As <ICacheService>().InstancePerRequest();


            MapperRegistration.Register(builder);

            var logger = LogManager.GetLogger(typeof(MvcApplication));

            builder.Register(c => logger).As <ILog>().SingleInstance();

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
            .Where(x => x.Name.EndsWith("Processor"))
            .AsImplementedInterfaces()
            .InstancePerRequest();

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
            .Where(x => x.Name.EndsWith("Service"))
            .AsImplementedInterfaces()
            .InstancePerRequest();

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
            .Where(x => x.Name.EndsWith("Repository"))
            .AsSelf()
            .InstancePerRequest();

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }