IEnumerable <Type> FindHandlers(IHandlerCache handlerCache) { var thisAssmebly = this.GetType().Assembly; var handlers = handlerCache.AllHandlerTypes.Where(handler => { if (handler.IsAbstract) { return(false); } if (handler.Assembly != thisAssmebly) { return(false); } // Don't register handlers from other areas if (handler.Namespace.Contains(".Areas.") && !handler.Namespace.Contains(".Areas." + this.AreaName + ".") && !handler.Namespace.Contains(".Areas.Common.")) { return(false); } return(true); }).ToArray(); #if DEBUG var handlerNames = string.Join("\n", handlers.Select(h => h.FullName)); log.Debug("Found {handlerCount} handler(s) for {Area}\n{Handlers}", handlers.Length, this.AreaName, handlerNames); #endif return(handlers); }
public HandleMessageMiddleware(IHandlerCache handlerCache, IServiceProvider serviceProvider, IBusConfig busConfig, ILogger <HandleMessageMiddleware> logger) { this.handlerCache = handlerCache ?? throw new ArgumentNullException(nameof(handlerCache)); this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); this.busConfig = busConfig ?? throw new ArgumentNullException(nameof(busConfig)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
void RegisterRoute(IHandlerCache handlerCache, ICollection <IRoute> routeCollection, KeyValuePair <string, List <Tuple <Type, RouteDefinition> > > routeRegistration) { // If there is only a single handler for this route if (routeRegistration.Value.Count == 1) { this.RegisterHandler(routeCollection, routeRegistration.Value[0].Item1, routeRegistration.Key, routeRegistration.Value[0].Item2.Localised, routeRegistration.Value[0].Item2.Personalised, routeRegistration.Value[0].Item2.RequestTypes, 0); return; } // Else we have mutliple handlers for this route var handlersAndMethods = new List <Tuple <Type, RouteDefinition, HttpMethod> >(); foreach (var handler in routeRegistration.Value) { var handledMethods = handlerCache.GetHandledMethods(handler.Item1); handlersAndMethods.Add(new Tuple <Type, RouteDefinition, HttpMethod>(handler.Item1, handler.Item2, handledMethods)); } var orderedEnumerable = handlersAndMethods.OrderBy(x => (x.Item3 != 0 ? "0" : "1") + (x.Item2.RequestTypes > 0 ? "0" : "1")); foreach (var handler in orderedEnumerable) { this.RegisterHandler(routeCollection, handler.Item1, routeRegistration.Key, handler.Item2.Localised, handler.Item2.Personalised, handler.Item2.RequestTypes, handler.Item3); } }
public virtual void RegisterArea(IHandlerCache handlerCache, ICollection <IRoute> routeCollection) { var handlers = this.FindHandlers(handlerCache); var hash = this.HashRoutes(handlers); // TODO: only include these when in dev mode this.MapRoute(routeCollection, "/" + this.AreaName + ".css", typeof(AreaCssHandler), false, false); this.MapRoute(routeCollection, "/" + this.AreaName + ".js", typeof(AreaJavascriptHandler), false, false); this.MapRoute(routeCollection, "/areas/" + this.AreaName + "/assets/{*path}", typeof(AreaStaticAssetHandler), false, false); foreach (var routeRegistration in hash) { this.RegisterRoute(handlerCache, routeCollection, routeRegistration); } }
public virtual void RegisterArea(IHandlerCache handlerCache, ICollection <IRoute> routeCollection) { var handlers = this.FindHandlers(handlerCache); var hash = this.HashRoutes(handlers); if (this.addAssetHandlers) { this.MapRoute(routeCollection, "/" + this.AreaName + ".css", typeof(AreaCssHandler), false, false); this.MapRoute(routeCollection, "/" + this.AreaName + ".js", typeof(AreaJavascriptHandler), false, false); this.MapRoute(routeCollection, "/areas/" + this.AreaName + "/assets/{*path}", typeof(AreaStaticAssetHandler), false, false); routeCollection.Add(new ViewJsRoute("/areas/" + this.AreaName)); } foreach (var routeRegistration in hash) { this.RegisterRoute(handlerCache, routeCollection, routeRegistration); } }
public WorkerStartupTask(IBusConfig busConfig, IObjectFactory objectFactory, IHandlerCache handlerCache) { this.busConfig = busConfig ?? throw new ArgumentNullException(nameof(busConfig)); this.objectFactory = objectFactory ?? throw new ArgumentNullException(nameof(objectFactory)); this.handlerCache = handlerCache ?? throw new ArgumentNullException(nameof(handlerCache)); }
public HandleMessageMiddleware(IHandlerCache handlerCache, IObjectFactory objectFactory, IBusConfig busConfig) { this.handlerCache = handlerCache ?? throw new ArgumentNullException(nameof(handlerCache)); this.objectFactory = objectFactory ?? throw new ArgumentNullException(nameof(objectFactory)); this.busConfig = busConfig ?? throw new ArgumentNullException(nameof(busConfig)); }
public LoadHandlers(IHandlerCache handlerCache) { this.handlerCache = handlerCache ?? throw new ArgumentNullException(nameof(handlerCache)); }
public MessageDeserilizationMiddleware(IBodySerializer bodySerializer, IHandlerCache handlerCache) { this.bodySerializer = bodySerializer ?? throw new ArgumentNullException(nameof(bodySerializer)); this.handlerCache = handlerCache ?? throw new ArgumentNullException(nameof(handlerCache)); }