Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(CarrinhoDeCompras.UI.App_Start.NinjectWebCommon), "Start")]
  2. [assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(CarrinhoDeCompras.UI.App_Start.NinjectWebCommon), "Stop")]
  3.  
  4. namespace CarrinhoDeCompras.UI.App_Start
  5. {
  6. using System;
  7. using System.Web;
  8.  
  9. using Microsoft.Web.Infrastructure.DynamicModuleHelper;
  10.  
  11. using Ninject;
  12. using Ninject.Web.Common;
  13. using CarrinhoDeCompras.Infra.CrossCutting.IoC.Modulos;
  14.  
  15. public static class NinjectWebCommon
  16. {
  17. private static readonly Bootstrapper bootstrapper = new Bootstrapper();
  18.  
  19. /// <summary>
  20. /// Starts the application
  21. /// </summary>
  22. public static void Start()
  23. {
  24. DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
  25. DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
  26. bootstrapper.Initialize(CreateKernel);
  27. }
  28.  
  29. /// <summary>
  30. /// Stops the application.
  31. /// </summary>
  32. public static void Stop()
  33. {
  34. bootstrapper.ShutDown();
  35. }
  36.  
  37. /// <summary>
  38. /// Creates the kernel that will manage your application.
  39. /// </summary>
  40. /// <returns>The created kernel.</returns>
  41. private static IKernel CreateKernel()
  42. {
  43. var kernel = new StandardKernel();
  44. try
  45. {
  46. kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
  47. kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
  48.  
  49. RegisterServices(kernel);
  50. return kernel;
  51. }
  52. catch
  53. {
  54. kernel.Dispose();
  55. throw;
  56. }
  57. }
  58.  
  59. /// <summary>
  60. /// Load your modules or register your services here!
  61. /// </summary>
  62. /// <param name="kernel">The kernel.</param>
  63. private static void RegisterServices(IKernel kernel)
  64. {
  65. kernel.Load(new ModulosNinject());
  66. }
  67. }
  68. }
  69.  
  70. using Ninject.Modules;
  71. using CarrinhoDeCompras.Application.Interfaces;
  72. using CarrinhoDeCompras.Application.Services;
  73. using CarrinhoDeCompras.Domain.Interfaces.Repositorios;
  74. using CarrinhoDeCompras.Domain.Interfaces.Services;
  75. using CarrinhoDeCompras.Domain.Services;
  76. using CarrinhoDeCompras.Infra.Data.EF.Repositorios;
  77.  
  78. namespace CarrinhoDeCompras.Infra.CrossCutting.IoC.Modulos
  79. {
  80. public class ModulosNinject : NinjectModule
  81. {
  82. public override void Load()
  83. {
  84. Bind(typeof(IAppServiceBase<>)).To(typeof(AppServiceBase<>));
  85. Bind<IAppServiceCategories>().To<AppServiceCategories>();
  86. Bind<IAppServiceCustomerDemographics>().To<AppServiceCustomerDemographics>();
  87. Bind<IAppServiceCustomers>().To<AppServiceCustomers>();
  88. Bind<IAppServiceEmployees>().To<AppServiceEmployees>();
  89. Bind<IAppServiceOrderDetails>().To<AppServiceOrderDetails>();
  90. Bind<IAppServiceOrders>().To<AppServiceOrders>();
  91. Bind<IAppServiceProducts>().To<AppServiceProducts>();
  92. Bind<IAppServiceRegion>().To<AppServiceRegion>();
  93. Bind<IAppServiceShippers>().To<AppServiceShippers>();
  94. Bind<IAppServiceSuppliers>().To<AppServiceSuppliers>();
  95. Bind<IAppServiceTerritories>().To<AppServiceTerritories>();
  96.  
  97. Bind(typeof(IServiceBase<>)).To(typeof(ServiceBase<>));
  98. Bind<IServiceCategories>().To<ServiceCategories>();
  99. Bind<IServiceCustomerDemographics>().To<ServiceCustomerDemographics>();
  100. Bind<IServiceCustomers>().To<ServiceCustomers>();
  101. Bind<IServiceEmployees>().To<ServiceEmployees>();
  102. Bind<IServiceOrderDetails>().To<ServiceOrderDetails>();
  103. Bind<IServiceOrders>().To<ServiceOrders>();
  104. Bind<IServiceProducts>().To<ServiceProducts>();
  105. Bind<IServiceRegion>().To<ServiceRegion>();
  106. Bind<IServiceShippers>().To<ServiceShippers>();
  107. Bind<IServiceSuppliers>().To<ServiceSuppliers>();
  108. Bind<IServiceTerritories>().To<ServiceTerritories>();
  109.  
  110. Bind(typeof(IRepositorioBase<>)).To(typeof(RepositorioBase<>));
  111. Bind<IRepositorioCategories>().To<RepositorioCategories>();
  112. Bind<IRepositorioCustomerDemographics>().To<RepositorioCustomerDemographics>();
  113. Bind<IRepositorioCustomers>().To<RepositorioCustomers>();
  114. Bind<IRepositorioEmployees>().To<RepositorioEmployees>();
  115. Bind<IRepositorioOrderDetails>().To<RepositorioOrderDetails>();
  116. Bind<IRepositorioOrders>().To<RepositorioOrders>();
  117. Bind<IRepositorioProducts>().To<RepositorioProducts>();
  118. Bind<IRepositorioRegion>().To<RepositorioRegion>();
  119. Bind<IRepositorioShippers>().To<RepositorioShippers>();
  120. Bind<IRepositorioSuppliers>().To<RepositorioSuppliers>();
  121. Bind<IRepositorioTerritories>().To<RepositorioTerritories>();
  122. }
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement