Beispiel #1
0
        public static void RegisterDependencies()
        {
            Container = new Container(cfg =>
            {
                cfg.Scan(scan =>
                {
                    scan.AssembliesFromApplicationBaseDirectory(
                        assembly => assembly.FullName.EndsWith(".Tests") == false);
                    scan.LookForRegistries();

                    scan.AssemblyContainingType<ListProductQuery>();
                    scan.AssemblyContainingType<IMediator>();
                    scan.WithDefaultConventions();
                    scan.AddAllTypesOf(typeof (IRequestHandler<,>));

                    scan.ConnectImplementationsToTypesClosing(typeof (AbstractValidator<>));
                });

                cfg.For<TextWriter>().Use(Console.Out);

                cfg.For(typeof (IRequestHandler<,>)).DecorateAllWith(typeof (ValidatorHandler<,>));

                cfg.For<IDatabaseAdapter>().Use<SqLiteDatabaseAdapter>();
            });

            var serviceLocator = new StructureMapServiceLocator(Container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            Container.Configure(cfg => cfg.For<ServiceLocatorProvider>().Use(serviceLocatorProvider));

            DependencyResolver.SetResolver(new StructureMapDependencyResolver(Container));
            Dependency.SetupContainer(Container);
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var container = new Container();
            container.Register<UsersController, UsersController>();
            container.Register<IUserRepository, UserRepository>(LifestyleType.Singleton);

            ControllerBuilder.Current.SetControllerFactory(new CustomControllerFactory(container));
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), o => o.EnableRetryOnFailure()));

            services.Configure<DRSConfig>(Configuration.GetSection("DRS"));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            //services.AddReact();

            services
                .AddMvc(
                    options =>
                    {
                        options.Conventions.Add(new FeatureConvention());
                        options.Filters.Add(new ValidateModelStateFilter());
                        options.Filters.Add(new ApiExceptionFilter());
                    })
                .AddRazorOptions(options =>
                {
                    // {0} - Action Name
                    // {1} - Controller Name
                    // {2} - Area Name
                    // {3} - Feature Name
                    //options.AreaViewLocationFormats.Clear();
                    options.AreaViewLocationFormats.Add("/Areas/{2}/Features/{3}/{1}/{0}.cshtml");
                    options.AreaViewLocationFormats.Add("/Areas/{2}/Features/{3}/{0}.cshtml");
                    options.AreaViewLocationFormats.Add("/Areas/{2}/Features/Shared/{0}.cshtml");
                    options.AreaViewLocationFormats.Add("/Areas/Shared/{0}.cshtml");
                    // replace normal view location entirely
                    //options.ViewLocationFormats.Clear();
                    options.ViewLocationFormats.Add("/Features/{3}/{1}/{0}.cshtml");
                    options.ViewLocationFormats.Add("/Features/{3}/{0}.cshtml");
                    options.ViewLocationFormats.Add("/Features/Shared/{0}.cshtml");

                    options.ViewLocationExpanders.Add(new FeatureViewLocationExpander());
                })
                .AddJsonOptions(
                    options =>
                    {
                        options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                    })
                .AddFluentValidation(cfg => { cfg.RegisterValidatorsFromAssemblyContaining<Startup>(); });

            services.AddAutoMapper(typeof(Startup));

            Mapper.AssertConfigurationIsValid();

            services.AddMediatR(typeof(Startup));

            var container = new Container(cfg => { cfg.AddRegistry<WebRegistry>(); });

            // populates structuremap with .NET services

            container.Populate(services);

            return container.GetInstance<IServiceProvider>();
        }
Beispiel #4
0
 public IContainer CreateContainer()
 {
     var kernel = new StandardKernel();
     var container = new Container(kernel);
     return container;
 }
Beispiel #5
0
 protected override IContainer CreateContainer()
 {
     var unityContainer = new UnityContainer ();
     var container = new Container (unityContainer);
     return container;
 }
 public IContainer CreateContainer()
 {
     Kernel = new StandardKernel(new ConfigurationModule());
     var container = new Container(Kernel);
     return container;
 }
Beispiel #7
0
 private static void RegisterDatabase(Container container)
 {
     container.RegisterInstance(typeof(DatabaseDelegator), new DatabaseDelegator());
     container.RegisterInstance(typeof(DatabaseDelegator), "CustomedDb", new DatabaseDelegator("CustomedDb"));
 }
Beispiel #8
0
 protected abstract void InitSite(Container container);
Beispiel #9
0
 private void RegisterInterceptor(Container container)
 {
     container.RegisterType(typeof(RetryCallHandler), new ContainerControlledLifetimeManager());
     container.RegisterType(typeof(TransactionCallHandler), new ContainerControlledLifetimeManager());
 }