Example #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var ambientDbLocater = new AmbientDbContextLocator();

            var container = new Container();
            container.Options.DefaultScopedLifestyle = new LifetimeScopeLifestyle();

            container.Register<IAmbientDbContextLocator, AmbientDbContextLocator>(Lifestyle.Singleton);
            container.Register<IUnitOfWork>(() => new EFUnitOfWork(), Lifestyle.Scoped);

            container.Register<IUnitOfWorkFactory>(
                () => new EFUnitOfWorkFactory(System.Data.IsolationLevel.ReadUncommitted));

            container.Register<IClienteRepository, ClienteRepository>();
            container.Register<IClientesService, ClientesService>();

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.RegisterMvcIntegratedFilterProvider();

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        /// <summary>
        /// Initialises IoC on the website
        /// </summary>
        public static void Initialise()
        {
            var container = new Container();
            container.Options.ConstructorResolutionBehavior =
                new T4MvcControllerConstructorResolutionBehavior(container.Options.ConstructorResolutionBehavior);

            // Register the MVC controls
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.RegisterMvcAttributeFilterProvider();
            container.Register<ITempDataProvider, CookieTempDataProvider>();

            // The other MVC stuff
            //container.Register<ITempDataProvider, CookieTempDataProvider>();
            // Register the other ASP.NET MVC stuff
            // TODO: Figure out how to do this properly - http://simpleinjector.codeplex.com/discussions/430939
            //container.RegisterPerWebRequest<RequestContext>(() => HttpContext.Current.Request.RequestContext);
            //container.RegisterPerWebRequest<UrlHelper>(() => new UrlHelper(container.GetInstance<RequestContext>()));

            container.RegisterPerWebRequest<IWebCache>(config => config.WebCacheType);

            // Initialise all the standard stuff
            Ioc.Initialise(container, new WebRequestLifestyle());

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        public static void Initialize()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            InitializeContainer(container);

            container.RegisterPerWebRequest(() =>
            {
                if (HttpContext.Current != null && HttpContext.Current.Items["owin.Enviroment"] == null && container.IsVerifying)
                {
                    return new OwinContext().Authentication;
                }

                return HttpContext.Current.GetOwinContext().Authentication;
            });

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
Example #4
0
        private void InitializeContainer(IApplicationBuilder app)
        {
            //add application presentation components
            container.RegisterMvcControllers(app);
            container.RegisterMvcViewComponents(app);

            //add application services. For instance
            //================================================APPLICATION========================================================
            container.Register(typeof(InterfaceAppServiceBase <>), typeof(AppServiceBase <>).Assembly, Lifestyle.Scoped);
            container.Register <InterfaceCategoriaAppService, CategoriaAppService>(Lifestyle.Scoped);
            container.Register <InterfaceClienteAppService, ClienteAppService>(Lifestyle.Scoped);
            container.Register <InterfaceProdutoAppService, ProdutoAppService>(Lifestyle.Scoped);
            container.Register <InterfaceImpostoAppService, ImpostoAppService>(Lifestyle.Scoped);

            //================================================DOMAIN============================================================
            container.Register(typeof(InterfaceServiceBase <>), typeof(ServiceBase <>).Assembly, Lifestyle.Scoped);
            container.Register <InterfaceCategoriaService, CategoriaService>(Lifestyle.Scoped);
            container.Register <InterfaceClienteService, ClienteService>(Lifestyle.Scoped);
            container.Register <InterfaceProdutoService, ProdutoService>(Lifestyle.Scoped);
            container.Register <InterfaceImpostoService, ImpostoService>(Lifestyle.Scoped);

            //===============================================INFRASTRUCTURE=====================================================
            container.Register(typeof(InterfaceRepositoryBase <>), typeof(RepositoryBase <>).Assembly, Lifestyle.Scoped);
            container.Register <InterfaceCategoriaRepository, CategoriaRepository>(Lifestyle.Scoped);
            container.Register <InterfaceClienteRepository, ClienteRepository>(Lifestyle.Scoped);
            container.Register <InterfaceProdutoRepository, ProdutoRepository>(Lifestyle.Scoped);
            container.Register <InterfaceImpostoRepository, ImpostoRepository>(Lifestyle.Scoped);

            //allow Simple Injector to resolve services from ASP.NET Core
            container.AutoCrossWireAspNetComponents(app);
        }
Example #5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // Simple Injection Setup
            var container = new Container();

            // SI Controllers Dependency Injection
            container.Register<IUserHelper, UserHelper>(Lifestyle.Singleton);
            container.Register<IConfigurationHelper, ConfigurationHelper>(Lifestyle.Singleton);
            container.Register<IErrorSignaler, ErrorSignaler>(Lifestyle.Singleton);
            container.Register<IAddressResource, AddressResource>(Lifestyle.Singleton);
            container.Register<IHobbyResource, HobbyResource>(Lifestyle.Singleton);
            container.Register<IEducationResource, EducationResource>(Lifestyle.Singleton);
            container.Register<IUsersResource, UsersResource>(Lifestyle.Singleton);
            container.Register<IMediaResource, MediaResource>(Lifestyle.Singleton);
            container.Register<INotificationResource, NotificationResource>(Lifestyle.Singleton);

            // SI Token Identity Registers
            container.Register<IdentityDbContext<BlogUser>, BlogIdentityDbContext>(Lifestyle.Singleton);
            container.Register<IUserStore<BlogUser>, BlogUserStore>(Lifestyle.Singleton);
            container.Register<IBlogDbRepository, BlogDbRepository>(Lifestyle.Singleton);
            container.Register<BlogUserManager, BlogUserManager>(Lifestyle.Singleton);

            // SI Registrations
            container.RegisterMvcControllers(System.Reflection.Assembly.GetExecutingAssembly());
            container.RegisterMvcIntegratedFilterProvider();

            container.Verify();

            // Register the dependency resolver.
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        public static void Initialize()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            // Chamada dos módulos do Simple Injector
            InitializeContainer(container);

            // Necessário para registrar o ambiente do Owin que é dependência do Identity
            // Feito fora da camada de IoC para não levar o System.Web para fora
            container.RegisterPerWebRequest(() =>
            {
                if (HttpContext.Current != null && HttpContext.Current.Items["owin.Environment"] == null && container.IsVerifying())
                {
                    return new OwinContext().Authentication;
                }
                return HttpContext.Current.GetOwinContext().Authentication;

            });

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        public static void Register()
        {
            // Create the container as usual.
            Container container = new Container();

            // services
            container.Register<IManagerCustomerRepository, ManagerCustomerRepository>();

            // data

            // Register your types, for instance using the RegisterWebApiRequest
            // extension from the integration package:
            container.RegisterMvcControllers(
                System.Reflection.Assembly.GetExecutingAssembly());

            container.RegisterMvcAttributeFilterProvider();

            // This is an extension method from the integration package.

            // verify its all ok
            container.Verify();

            // add dependency
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Example #8
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Allow Any Certificates
            // This should not be the same in Production
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

            // Create the container as usual.
            var container = new Container();
            container.Options.PropertySelectionBehavior = new ImportPropertySelectionBehavior();
            container.Register<IErrorSignaler, ErrorSignaler>(Lifestyle.Singleton);
            container.Register<IHttpClientHelper, HttpClientHelper>(Lifestyle.Singleton);
            container.Register<IConfigurationHelper, ConfigurationHelper>(Lifestyle.Singleton);

            // SI Attributes Dependency Injection
            container.RegisterInitializer<BlogApiAuthorizationAttribute>(a => a.ErrorSignaler = container.GetInstance<ErrorSignaler>());
            container.RegisterInitializer<BlogAuthorizationAttribute>(a => a.ErrorSignaler = container.GetInstance<ErrorSignaler>());

            // This is an extension method from the integration package.
            container.RegisterMvcControllers(System.Reflection.Assembly.GetExecutingAssembly());
            container.RegisterMvcIntegratedFilterProvider();
            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjector.Integration.Web.Mvc.SimpleInjectorDependencyResolver(container));
        }
        public static void Configure(Container container)
        {
            container.RegisterMvcControllers(typeof(MvcConfig).Assembly);
            container.RegisterMvcIntegratedFilterProvider();

            RouteTable.Routes.MapMvcAttributeRoutes();
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Example #10
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterWebApiFilters(GlobalConfiguration.Configuration.Filters);
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            FormatConfig.RegisterFormats(GlobalConfiguration.Configuration.Formatters);

            // Allow Any Certificates
            // This should not be the same in Production
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
            
            // Simple Injection Setup
            var container = new Container();
            container.Options.PropertySelectionBehavior = new ImportPropertySelectionBehavior();

            // SI Controllers registry
            container.Register<ICommentsResource, CommentsResource>(Lifestyle.Singleton);
            container.Register<ICommunityResource, CommunityResource>(Lifestyle.Singleton);
            container.Register<ICommentLikesResource, CommentLikesResource>(Lifestyle.Singleton);
            container.Register<IPostsResource, PostsResource>(Lifestyle.Singleton);
            container.Register<IUsersResource, UsersResource>(Lifestyle.Singleton);
            container.Register<IPostLikesResource, PostLikesResource>(Lifestyle.Singleton);
            container.Register<IPostContentsResource, PostContentsResource>(Lifestyle.Singleton);
            container.Register<IMediaResource, MediaResource>(Lifestyle.Singleton);
            container.Register<IAlbumResource, AlbumResource>(Lifestyle.Singleton);
            container.Register<IEducationResource, EducationResource>(Lifestyle.Singleton);
            container.Register<IHobbyResource, HobbyResource>(Lifestyle.Singleton);
            container.Register<IAddressResource, AddressResource>(Lifestyle.Singleton);
            container.Register<ITagsResource, TagsResource>(Lifestyle.Singleton);
            container.Register<IViewCountResource, ViewCountResource>(Lifestyle.Singleton);
            container.Register<IChatMessagesResource, ChatMessagesResource>(Lifestyle.Singleton);

            // SI Helpers and Utilities registry
            container.Register<IImageHelper, ImageHelper>(Lifestyle.Singleton);
            container.Register<IErrorSignaler, ErrorSignaler>(Lifestyle.Singleton);
            container.Register<IHttpClientHelper, HttpClientHelper>(Lifestyle.Singleton);
            container.Register<IConfigurationHelper, ConfigurationHelper>(Lifestyle.Singleton);

            // SI Token Identity registry
            container.Register<IdentityDbContext<BlogUser>, BlogIdentityDbContext>(Lifestyle.Singleton);
            container.Register<IUserStore<BlogUser>, BlogUserStore>(Lifestyle.Singleton);
            container.Register<IBlogDbRepository, BlogDbRepository>(Lifestyle.Singleton);
            container.Register<BlogUserManager, BlogUserManager>(Lifestyle.Singleton);

            // SI Registrations
            container.RegisterMvcControllers(System.Reflection.Assembly.GetExecutingAssembly());
            container.RegisterMvcIntegratedFilterProvider();
            container.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);

            container.Verify();

            // Register the dependency resolver.
            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.EnsureInitialized();
        }
 public static void Register()
 {
     DependencyInjectionContainer = new Container();
     DependencyInjectionContainer.RegisterTypes();
     DependencyInjectionContainer.RegisterMvcControllers(Assembly.GetExecutingAssembly());
     DependencyInjectionContainer.RegisterMvcAttributeFilterProvider();
     DependencyInjectionContainer.Verify();
     DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(DependencyInjectionContainer));
 }
		public static void SetupIoc()
		{
			var container = new Container();
			SetupDependencies(container);
			container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
			container.RegisterMvcIntegratedFilterProvider();
			container.Verify();
			DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
		}
 /// <summary>
 /// Initialize the container and register it as MVC3 Dependency Resolver.
 /// </summary>
 public static void Initialize()
 {
     var container = new Container();
       InitializeContainer(container);
       container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
       container.RegisterMvcAttributeFilterProvider();
       container.Verify();
       DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
       GlobalHost.DependencyResolver = new HubDependencyResolver(container);
 }
        /// <summary>Initialize the container and register it as MVC Dependency Resolver.</summary>
        public static void InitializeInjector(Container container)
        {
            InitializeContainer(container);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.RegisterMvcIntegratedFilterProvider();

            #if DEBUG
            container.Verify();
            #endif
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BootstrapBundleConfig.RegisterBundles();

            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            container.RegisterSingleton<ILinqToLdapLogger>(new SimpleTextLogger());

            container.RegisterSingleton<ILdapConfiguration>(() =>
            {
                var config = new LdapConfiguration()
                    .MaxPageSizeIs(50)
                    .LogTo(container.GetInstance<ILinqToLdapLogger>());

                //Note the optional parameters available on AddMapping.
                //We can perform "late" mapping on certain values, 
                //even for auto and attribute based mapping.
                config.AddMapping(new OrganizationalUnitMap())
                      .AddMapping(new AttributeClassMap<User>());

                // I explicitly mapped User, but I can also let it 
                // get mapped the first time we query for users.
                // This only applies to auto and attribute-based mapping.

                config.ConfigurePooledFactory("directory.utexas.edu")
                      .AuthenticateBy(AuthType.Anonymous)
                      .MinPoolSizeIs(0)
                      .MaxPoolSizeIs(5)
                      .UsePort(389)
                      .ProtocolVersion(3);

                return config;
            });

            //simple context per request only when requested
            container.Register<IDirectoryContext>(() => container.GetInstance<ILdapConfiguration>().CreateContext(), Lifestyle.Scoped);

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
            
            container.Verify();
        }
        /// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
        public static void Initialize()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            SetupDataContext(container);
            SetupServices(container);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.Verify();
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        public static void Initialize()
        {
            var container = new Container();

            InitializeContainer(container);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        public static Container CreateContainer() {
            var container = new Container();
            container.Options.AllowOverridingRegistrations = true;
            container.Options.PropertySelectionBehavior = new InjectAttributePropertySelectionBehavior();

            container.RegisterPackage<Bootstrapper>();

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.RegisterMvcAttributeFilterProvider();

            return container;
        }
Example #19
0
        public static void RegisterSimpleInjector()
        {
            var container = new SimpleInjector.Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            RegisterServices(container);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Example #20
0
        private void InitializeContainer(IApplicationBuilder app)
        {
            // Add application presentation components:
            _container.RegisterMvcControllers(app);
            _container.RegisterMvcViewComponents(app);

            // Add application services. For instance:
            //_container.Register<IUserService, UserService>(Lifestyle.Scoped);

            // Allow Simple Injector to resolve services from ASP.NET Core.
            _container.AutoCrossWireAspNetComponents(app);
        }
        /// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
        public static void Initialize()
        {
            // Did you know the container can diagnose your configuration? Go to: https://bit.ly/YE8OJj.
            var container = new Container();

            InitializeContainer(container);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        public static void SetResolver() {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.RegisterMvcIntegratedFilterProvider();

            RegisterDependencies(container);

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        /// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
        public static void Initialize()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            InitializeContainer(container);

            container.RegisterMvcControllers(typeof(SimpleInjectorInitializer).Assembly);

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        public static Container RegisterServices(Assembly mvcControllersAssembly)
        {
            var container = new Container();

            container.RegisterPackages(new[] { Assembly.GetExecutingAssembly() });

            container.RegisterMvcControllers(mvcControllersAssembly);

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));

            return container;
        }
Example #25
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            var dataModelAssembly = typeof(IUnitOfWork).Assembly;

            var dataModelRegistrations =
                from type in dataModelAssembly.GetExportedTypes()
                where type.Namespace == "DanCanKanBan.DataModel.UnitOfWork"
                where type.GetInterfaces().Any()
                select new { Service = type.GetInterfaces().Single(), Implementation = type };

            foreach (var reg in dataModelRegistrations)
            {
                container.Register(reg.Service, reg.Implementation, Lifestyle.Scoped);
            }

            var serviceAssembly = typeof(IUserService).Assembly;

            var serviceRegistrations =
               from type in serviceAssembly.GetExportedTypes()
               where type.Namespace == "DanCanKanBan.Services.Services"
               where type.GetInterfaces().Any()
               select new { Service = type.GetInterfaces().Single(), Implementation = type };

            foreach (var reg in serviceRegistrations)
            {
                container.Register(reg.Service, reg.Implementation, Lifestyle.Scoped);
            }

            container.Register<IConfigurationSettings, WebConfigurationSettings>(Lifestyle.Scoped);
            container.Register<IUserSession, WebUserSession>(Lifestyle.Scoped);

            // This is an extension method from the integration package.
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            // This is an extension method from the integration package as well.
            container.RegisterMvcIntegratedFilterProvider();

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        /// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
        public static void Initialize()
        {
            var container = new Container();
            
            InitializeContainer(container);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            
            container.RegisterMvcAttributeFilterProvider();
       
            // Using Entity Framework? Please read this: http://simpleinjector.codeplex.com/discussions/363935
            container.Verify();
            
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
 protected void Application_Start()
 {
     // default MVC stuff
     AreaRegistration.RegisterAllAreas();
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     // Simple Injector set up
     var container = new Container();
     container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
     // Register your stuff here  
     container.Register<ITestService, TestService>(Lifestyle.Scoped);
     container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
     container.RegisterMvcIntegratedFilterProvider();
     container.Verify();
     DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
 }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Code for registering our repository class and DI
            var container = new Container();
            container.Register<ICustomerRepository, CustomerRepository>();

            // This two extension method from integration package
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Example #29
0
        private void InjectDependencies()
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            container.Register<IChatService, ChatService>(Lifestyle.Scoped);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.RegisterMvcIntegratedFilterProvider();

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
        public static void Initialize()
        {
            _container = new Container();
            _container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            InitializeContainer(_container);
            _container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            _container.RegisterMvcIntegratedFilterProvider();

            var dependencyResolver = new SimpleInjectorDependencyResolver(_container);
            DependencyResolver.SetResolver(dependencyResolver);
            DomainEvent.Container = new DomainEventContainer(dependencyResolver);

            _container.Verify();
        }
        public static void Initialize()
        {
            Container container = new Container();

            IRestContext context = DreamFactoryContext.Create();

            container.Register<IDatabaseApi>(() => context.Factory.CreateDatabaseApi(DreamFactoryContext.DbServiceName), Lifestyle.Transient);
            container.Register<ISystemAdminApi>(() => context.Factory.CreateSystemAdminApi(), Lifestyle.Transient);
            container.Register<IUserApi>(() => context.Factory.CreateUserApi(), Lifestyle.Transient);
            container.Register<IFilesApi>(() => context.Factory.CreateFilesApi(DreamFactoryContext.FileServiceName), Lifestyle.Transient);

            container.RegisterMvcControllers();
            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Example #32
0
        /// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
        public static void Initialize()
        {
            //// Did you know the container can diagnose your configuration? Go to: http://bit.ly/YE8OJj.
            var container = new Container();

            //Make call to Domain.IoC initializer
            Todo.Domain.IoC.SimpleInjectorInitializer.Initialize(container);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.RegisterMvcAttributeFilterProvider();

            container.Verify();

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

            var container = new Container();
            container.RegisterSingleton<ExamDBEntities>();
            container.Register<IBestSellingProductsDataSource, BestSellingProductsDataSource>(Lifestyle.Transient);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Example #34
0
        public static void Register()
        {
            // Create the container as usual.
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            // Register your types, for instance:
            container.Register <IPetRepository, PetRepository>(Lifestyle.Scoped);
            container.Register <IPetService, PetService>(Lifestyle.Scoped);
            container.Register <ApplicationDbContext, ApplicationDbContext>(Lifestyle.Scoped);

            // This is an extension method from the integration package.
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Example #35
0
        /// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
        public static void Initialize()
        {
            // Did you know the container can diagnose your configuration? Go to: http://bit.ly/YE8OJj.
            var container = new SimpleInjector.Container();

            container.Options.AllowOverridingRegistrations = true;

            var originalConstructorResolutionBehavior = container.Options.ConstructorResolutionBehavior;

            container.Options.ConstructorResolutionBehavior = new SimpleInjectorContainerResolutionBehavior(originalConstructorResolutionBehavior);

            InitializeContainer(container);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.RegisterMvcAttributeFilterProvider();

#if DEBUG
            //container.Verify();
#endif
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Example #36
0
        /// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
        public static void Initialize()
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            InitializeContainer(container);

            //container.Register(() =>
            //{
            //    if (HttpContext.Current != null && HttpContext.Current.Items["owin.Environment"] == null && container.IsVerifying())
            //    {
            //        return new OwinContext().Authentication;
            //    }
            //    return HttpContext.Current.GetOwinContext().Authentication;

            //});

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Example #37
0
        private void InitializeContainer(IApplicationBuilder app)
        {
            //add application presentation components
            container.RegisterMvcControllers(app);
            container.RegisterMvcViewComponents(app);

            #region Application
            //add application services. For instance
            //====================================================APPLICATION========================================================
            container.Register(typeof(IAppServiceBase <>), typeof(AppServiceBase <>).Assembly, Lifestyle.Scoped);
            //===============================Pessoa=================================================
            container.Register <IPessoaAppService, PessoaAppService>(Lifestyle.Scoped);
            container.Register <IPessoaTipoAppService, PessoaTipoAppService>(Lifestyle.Scoped);
            //==============================Tipos===================================================
            container.Register <IFisicaAppService, FisicaAppService>(Lifestyle.Scoped);
            container.Register <IJuridicaAppService, JuridicaAppService>(Lifestyle.Scoped);
            //==============================Clientes================================================
            container.Register <IClienteAppService, ClienteAppService>(Lifestyle.Scoped);

            //==============================Contatos================================================
            container.Register <IContatoAppService, ContatoAppService>(Lifestyle.Scoped);

            //===============================CONTATOS/EMAILS========================================
            //=============================Emails===================================================
            container.Register <IEmailAppService, EmailAppService>(Lifestyle.Scoped);
            //==============================Endereços===============================================
            container.Register <IEnderecoAppService, EnderecoAppService>(Lifestyle.Scoped);
            container.Register <IEnderecoClienteAppService, EnderecoClienteAppService>(Lifestyle.Scoped);
            container.Register <IEnderecoPessoaAppService, EnderecoPessoaAppService>(Lifestyle.Scoped);
            //=============================Telefones================================================
            container.Register <ITelefoneAppService, TelefoneAppService>(Lifestyle.Scoped);
            container.Register <ITelefoneTipoAppService, TelefoneTipoAppService>(Lifestyle.Scoped);

            //============================Compras===================================================
            //============================ControleEstoque===========================================
            container.Register <IEstoqueAppService, EstoqueAppService>(Lifestyle.Scoped);
            //============================Produção==================================================
            container.Register <ICategoriaAppService, CategoriaAppService>(Lifestyle.Scoped);
            container.Register <IProdutoAppService, ProdutoAppService>(Lifestyle.Scoped);
            //============================Vendas====================================================
            container.Register <IDetalhePedidoAppService, DetalhePedidoAppService>(Lifestyle.Scoped);
            container.Register <IDetalheVendaAppService, DetalheVendaAppService>(Lifestyle.Scoped);
            container.Register <IImpostoAppService, ImpostoAppService>(Lifestyle.Scoped);
            container.Register <IPedidoAppService, PedidoAppService>(Lifestyle.Scoped);
            container.Register <IVendaAppService, VendaAppService>(Lifestyle.Scoped);

            #endregion

            #region Domain
            //================================================DOMAIN===================================================================
            container.Register(typeof(IServiceBase <>), typeof(ServiceBase <>).Assembly, Lifestyle.Scoped);

            //==========================Pessoas==========================================================
            container.Register <IPessoaService, PessoaService>(Lifestyle.Scoped);
            container.Register <IPessoaTipoService, PessoaTipoService>(Lifestyle.Scoped);
            //==========================Tipos============================================================
            container.Register <IFisicaService, FisicaService>(Lifestyle.Scoped);
            container.Register <IJuridicaService, JuridicaService>(Lifestyle.Scoped);
            //==========================Clientes=========================================================
            container.Register <IClienteService, ClienteService>(Lifestyle.Scoped);

            //=========================Contatos==========================================================
            container.Register <IContatoService, ContatoService>(Lifestyle.Scoped);

            //============================CONTATOS/EMAILS================================================
            //==========================Emails===========================================================
            container.Register <IEmailService, EmailService>(Lifestyle.Scoped);
            //==========================Endereços========================================================
            container.Register <IEnderecoService, EnderecoService>(Lifestyle.Scoped);
            container.Register <IEnderecoPessoaService, EnderecoPessoaService>(Lifestyle.Scoped);
            container.Register <IEnderecoClienteService, EnderecoClienteService>(Lifestyle.Scoped);
            //==========================Telefone=========================================================
            container.Register <ITelefoneService, TelefoneService>(Lifestyle.Scoped);
            container.Register <ITelefoneTipoService, TelefoneTipoService>(Lifestyle.Scoped);

            //==========================Compras==========================================================

            //==========================ControleEstoque==================================================
            container.Register <IEstoqueService, EstoqueService>(Lifestyle.Scoped);
            //==========================Produção=========================================================
            container.Register <ICategoriaService, CategoriaService>(Lifestyle.Scoped);
            container.Register <IProdutoService, ProdutoService>(Lifestyle.Scoped);

            //==========================Vendas===========================================================
            container.Register <IDetalhePedidoService, DetalhePedidoService>(Lifestyle.Scoped);
            container.Register <IDetalheVendaService, DetalheVendaService>(Lifestyle.Scoped);
            container.Register <IImpostoService, ImpostoService>(Lifestyle.Scoped);
            container.Register <IPedidoService, PedidoService>(Lifestyle.Scoped);
            container.Register <IVendaService, VendaService>(Lifestyle.Scoped);

            #endregion

            #region Infrastructure
            //===============================================INFRASTRUCTURE==============================================================
            container.Register(typeof(IRepositoryBase <>), typeof(RepositoryBase <>).Assembly, Lifestyle.Scoped);
            //==========================Pessoas==========================================================
            container.Register <IPessoaRepository, PessoaRepository>(Lifestyle.Scoped);
            container.Register <IPessoaTipoRepository, PessoaTipoRepository>(Lifestyle.Scoped);
            //==========================Tipos============================================================
            container.Register <IJuridicaRepository, JuridicaRepository>(Lifestyle.Scoped);
            container.Register <IFisicaRepository, FisicaRepository>(Lifestyle.Scoped);
            //==========================Clientes=========================================================
            container.Register <IClienteRepository, ClienteRepository>(Lifestyle.Scoped);

            //==========================Contatos=========================================================
            container.Register <IContatoRepository, ContatoRepository>(Lifestyle.Scoped);

            //=============================CONTATOS/EMAILS===============================================
            //==========================Emails===========================================================
            container.Register <IEmailRepository, EmailRepository>(Lifestyle.Scoped);
            //==========================Endereços========================================================
            container.Register <IEnderecoRepository, EnderecoRepository>(Lifestyle.Scoped);
            container.Register <IEnderecoClienteRepository, EnderecoClienteRepository>(Lifestyle.Scoped);
            container.Register <IEnderecoPessoaRepository, EnderecoPessoaRepository>(Lifestyle.Scoped);
            //==========================Telefone=========================================================
            container.Register <ITelefoneRepository, TelefoneRepository>(Lifestyle.Scoped);
            container.Register <ITelefoneTipoRepository, TelefoneTipoRepository>(Lifestyle.Scoped);
            //==========================Compras==========================================================
            //==========================ControleEstoque==================================================
            container.Register <IEstoqueRepository, EstoqueRepository>(Lifestyle.Scoped);
            //==========================Produção=========================================================
            container.Register <ICategoriaRepository, CategoriaRepository>(Lifestyle.Scoped);
            container.Register <IProdutoRepository, ProdutoRepository>(Lifestyle.Scoped);
            //==========================Vendas===========================================================
            container.Register <IDetalhePedidoRepository, DetalhePedidoRepository>(Lifestyle.Scoped);
            container.Register <IDetalheVendaRepository, DetalheVendaRepository>(Lifestyle.Scoped);
            container.Register <IImpostoRepository, ImpostoRepository>(Lifestyle.Scoped);
            container.Register <IPedidoRepository, PedidoRepository>(Lifestyle.Scoped);
            container.Register <IVendaRepository, VendaRepository>(Lifestyle.Scoped);

            #endregion
            //allow Simple Injector to resolve services from ASP.NET Core
            container.AutoCrossWireAspNetComponents(app);
        }