diff --git a/vNext/src/BetterModules.Core.Web/Modules/Registration/DefaultWebModulesRegistration.cs b/vNext/src/BetterModules.Core.Web/Modules/Registration/DefaultWebModulesRegistration.cs index cc7f2e7..573800f 100644 --- a/vNext/src/BetterModules.Core.Web/Modules/Registration/DefaultWebModulesRegistration.cs +++ b/vNext/src/BetterModules.Core.Web/Modules/Registration/DefaultWebModulesRegistration.cs @@ -83,9 +83,9 @@ protected override void RegisterModuleDescriptor(ModuleRegistrationContext regis if (webContext != null) { var webDescriptor = (WebModuleDescriptor)webContext.ModuleDescriptor; - webDescriptor.RegisterModuleCommands(webContext, containerBuilder); - webDescriptor.RegisterModuleControllers(webContext, containerBuilder, controllerExtensions); - webDescriptor.RegisterCustomRoutes(webContext, containerBuilder); + webDescriptor.RegisterModuleCommands(webContext, services); + webDescriptor.RegisterModuleControllers(webContext, services, controllerExtensions); + webDescriptor.RegisterCustomRoutes(webContext, services); } base.RegisterModuleDescriptor(registrationContext, services); diff --git a/vNext/src/BetterModules.Core.Web/Modules/WebModuleDescriptor.cs b/vNext/src/BetterModules.Core.Web/Modules/WebModuleDescriptor.cs index 747f9e4..f17adac 100644 --- a/vNext/src/BetterModules.Core.Web/Modules/WebModuleDescriptor.cs +++ b/vNext/src/BetterModules.Core.Web/Modules/WebModuleDescriptor.cs @@ -2,14 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Web.Mvc; -using Autofac; using BetterModules.Core.Extensions; using BetterModules.Core.Modules; using BetterModules.Core.Modules.Registration; using BetterModules.Core.Web.Modules.Registration; using BetterModules.Core.Web.Mvc.Commands; using BetterModules.Core.Web.Mvc.Extensions; +using Microsoft.AspNet.Mvc; +using Microsoft.Framework.DependencyInjection; namespace BetterModules.Core.Web.Modules { @@ -59,8 +59,8 @@ public virtual string AreaName /// Registers a routes. /// /// The area registration context. - /// The container builder. - public virtual void RegisterCustomRoutes(WebModuleRegistrationContext context, ContainerBuilder containerBuilder) + /// + public virtual void RegisterCustomRoutes(WebModuleRegistrationContext context, IServiceCollection services) { } @@ -68,9 +68,9 @@ public virtual void RegisterCustomRoutes(WebModuleRegistrationContext context, C /// Registers module controller types. /// /// The area registration context. - /// The container builder. + /// /// The controller extensions. - public virtual void RegisterModuleControllers(WebModuleRegistrationContext registrationContext, ContainerBuilder containerBuilder, IControllerExtensions controllerExtensions) + public virtual void RegisterModuleControllers(WebModuleRegistrationContext registrationContext, IServiceCollection services, IControllerExtensions controllerExtensions) { var controllerTypes = controllerExtensions.GetControllerTypes(GetType().Assembly); @@ -85,24 +85,25 @@ public virtual void RegisterModuleControllers(WebModuleRegistrationContext regis { namespaces.Add(controllerType.Namespace); } - - containerBuilder - .RegisterType(controllerType) - .AsSelf() - .Keyed(key) - .WithMetadata("ControllerType", controllerType) - .InstancePerDependency() - .PropertiesAutowired(PropertyWiringOptions.PreserveSetValues); + services.AddTransient(controllerType); + // TODO: register controllers with keys and metadata + //containerBuilder + // .RegisterType(controllerType) + // .AsSelf() + // .Keyed(key) + // .WithMetadata("ControllerType", controllerType) + // .InstancePerDependency() + // .PropertiesAutowired(PropertyWiringOptions.PreserveSetValues); } registrationContext.MapRoute( - string.Format("module_{0}_internal_routes", AreaName), - string.Format("{0}/{{controller}}/{{action}}", AreaName), - new - { - area = AreaName - }, - namespaces.ToArray()); + $"module_{AreaName}_internal_routes", + $"{AreaName}/{{controller}}/{{action}}", + new + { + area = AreaName + }, + namespaces.ToArray()); } } @@ -110,8 +111,8 @@ public virtual void RegisterModuleControllers(WebModuleRegistrationContext regis /// Registers the module command types. /// /// The area registration context. - /// The container builder. - public virtual void RegisterModuleCommands(WebModuleRegistrationContext registrationContext, ContainerBuilder containerBuilder) + /// + public virtual void RegisterModuleCommands(WebModuleRegistrationContext registrationContext, IServiceCollection services) { Assembly assembly = GetType().Assembly; @@ -122,14 +123,30 @@ public virtual void RegisterModuleCommands(WebModuleRegistrationContext registra typeof(ICommandOut<>), typeof(ICommand<,>) }; - - containerBuilder - .RegisterAssemblyTypes(assembly) - .Where(scan => commandTypes.Any(commandType => scan.IsAssignableToGenericType(commandType))) - .AsImplementedInterfaces() - .AsSelf() - .PropertiesAutowired() - .InstancePerLifetimeScope(); + var types = assembly + .GetExportedTypes() + .Where(type => commandTypes.Any(type.IsAssignableToGenericType)) + .ToList(); + foreach (var type in types) + { + services.AddScoped(type); + var interfaces = type + .GetInterfaces() + .Where(x => x.IsPublic && x != typeof (IDisposable)) + .ToList(); + foreach (var @interface in interfaces) + { + services.AddScoped(@interface, type); + } + } + // TODO: register commands + //containerBuilder + // .RegisterAssemblyTypes(assembly) + // .Where(scan => commandTypes.Any(commandType => scan.IsAssignableToGenericType(commandType))) + // .AsImplementedInterfaces() + // .AsSelf() + // .PropertiesAutowired() + // .InstancePerLifetimeScope(); } ///