Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(CarrinhoDeCompras.UI.App_Start.NinjectWebCommon), "Start")]
- [assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(CarrinhoDeCompras.UI.App_Start.NinjectWebCommon), "Stop")]
- namespace CarrinhoDeCompras.UI.App_Start
- {
- using System;
- using System.Web;
- using Microsoft.Web.Infrastructure.DynamicModuleHelper;
- using Ninject;
- using Ninject.Web.Common;
- using CarrinhoDeCompras.Infra.CrossCutting.IoC.Modulos;
- public static class NinjectWebCommon
- {
- private static readonly Bootstrapper bootstrapper = new Bootstrapper();
- /// <summary>
- /// Starts the application
- /// </summary>
- public static void Start()
- {
- DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
- DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
- bootstrapper.Initialize(CreateKernel);
- }
- /// <summary>
- /// Stops the application.
- /// </summary>
- public static void Stop()
- {
- bootstrapper.ShutDown();
- }
- /// <summary>
- /// Creates the kernel that will manage your application.
- /// </summary>
- /// <returns>The created kernel.</returns>
- private static IKernel CreateKernel()
- {
- var kernel = new StandardKernel();
- try
- {
- kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
- kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
- RegisterServices(kernel);
- return kernel;
- }
- catch
- {
- kernel.Dispose();
- throw;
- }
- }
- /// <summary>
- /// Load your modules or register your services here!
- /// </summary>
- /// <param name="kernel">The kernel.</param>
- private static void RegisterServices(IKernel kernel)
- {
- kernel.Load(new ModulosNinject());
- }
- }
- }
- using Ninject.Modules;
- using CarrinhoDeCompras.Application.Interfaces;
- using CarrinhoDeCompras.Application.Services;
- using CarrinhoDeCompras.Domain.Interfaces.Repositorios;
- using CarrinhoDeCompras.Domain.Interfaces.Services;
- using CarrinhoDeCompras.Domain.Services;
- using CarrinhoDeCompras.Infra.Data.EF.Repositorios;
- namespace CarrinhoDeCompras.Infra.CrossCutting.IoC.Modulos
- {
- public class ModulosNinject : NinjectModule
- {
- public override void Load()
- {
- Bind(typeof(IAppServiceBase<>)).To(typeof(AppServiceBase<>));
- Bind<IAppServiceCategories>().To<AppServiceCategories>();
- Bind<IAppServiceCustomerDemographics>().To<AppServiceCustomerDemographics>();
- Bind<IAppServiceCustomers>().To<AppServiceCustomers>();
- Bind<IAppServiceEmployees>().To<AppServiceEmployees>();
- Bind<IAppServiceOrderDetails>().To<AppServiceOrderDetails>();
- Bind<IAppServiceOrders>().To<AppServiceOrders>();
- Bind<IAppServiceProducts>().To<AppServiceProducts>();
- Bind<IAppServiceRegion>().To<AppServiceRegion>();
- Bind<IAppServiceShippers>().To<AppServiceShippers>();
- Bind<IAppServiceSuppliers>().To<AppServiceSuppliers>();
- Bind<IAppServiceTerritories>().To<AppServiceTerritories>();
- Bind(typeof(IServiceBase<>)).To(typeof(ServiceBase<>));
- Bind<IServiceCategories>().To<ServiceCategories>();
- Bind<IServiceCustomerDemographics>().To<ServiceCustomerDemographics>();
- Bind<IServiceCustomers>().To<ServiceCustomers>();
- Bind<IServiceEmployees>().To<ServiceEmployees>();
- Bind<IServiceOrderDetails>().To<ServiceOrderDetails>();
- Bind<IServiceOrders>().To<ServiceOrders>();
- Bind<IServiceProducts>().To<ServiceProducts>();
- Bind<IServiceRegion>().To<ServiceRegion>();
- Bind<IServiceShippers>().To<ServiceShippers>();
- Bind<IServiceSuppliers>().To<ServiceSuppliers>();
- Bind<IServiceTerritories>().To<ServiceTerritories>();
- Bind(typeof(IRepositorioBase<>)).To(typeof(RepositorioBase<>));
- Bind<IRepositorioCategories>().To<RepositorioCategories>();
- Bind<IRepositorioCustomerDemographics>().To<RepositorioCustomerDemographics>();
- Bind<IRepositorioCustomers>().To<RepositorioCustomers>();
- Bind<IRepositorioEmployees>().To<RepositorioEmployees>();
- Bind<IRepositorioOrderDetails>().To<RepositorioOrderDetails>();
- Bind<IRepositorioOrders>().To<RepositorioOrders>();
- Bind<IRepositorioProducts>().To<RepositorioProducts>();
- Bind<IRepositorioRegion>().To<RepositorioRegion>();
- Bind<IRepositorioShippers>().To<RepositorioShippers>();
- Bind<IRepositorioSuppliers>().To<RepositorioSuppliers>();
- Bind<IRepositorioTerritories>().To<RepositorioTerritories>();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement