public override void Spin(IRotorContext context) { var serviceLocator = GetServiceLocatorFromContext(context); var resolver = GetEmbeddedViewResolver(serviceLocator); var table = resolver.GetEmbeddedViews(); var embeddedProvider = new EmbeddedViewVirtualPathProvider(table); HostingEnvironment.RegisterVirtualPathProvider(embeddedProvider); }
public static void RegisterHostedApplication(this IHostedApplication hostedApplication, RouteCollection routeCollection) { var pathProvider = new EmbeddedViewVirtualPathProvider(hostedApplication.ApplicationName, hostedApplication.ApplicationContextType.Assembly); HostingEnvironment.RegisterVirtualPathProvider(pathProvider); hostedApplication.ApplicationContextType.Assembly.GetTypes().Where(a => a.IsSubclassOf(typeof(Controller))).ForEachAsParallel(a => { string controllerName = a.Name.Replace("Controller", string.Empty); string routeName = string.Format("{0}_{1}", hostedApplication.ApplicationName, controllerName); string routeUrl = hostedApplication.ApplicationName + "/" + controllerName + "/{action}/{id}"; routeCollection.MapRoute(name: routeName, url: routeUrl, defaults: new { controller = controllerName, action = "Index", id = UrlParameter.Optional }, constraints: null, namespaces: new string[] { a.Namespace }); }); }