Source/Routing/MqttRouteTableFactory.cs
/// <summary>
/// Given a list of assemblies, find all instances of MqttControllers and wire up routing for them. Instances of
/// controllers must inherit from MqttBaseController and be decorated with an MqttRoute attribute.
/// </summary>
/// <param name="assembly">Assemblies to scan for routes</param>
/// <returns></returns>
Given a list of assemblies, find all instances of MqttControllers and wire up routing for them. Instances of
controllers must inherit from MqttBaseController and be decorated with an MqttRoute attribute.
Given a list of assemblies find all instances of MqttControllers and wire up routing for them . Instances of controllers must inherit from MqttBaseController and be decorated with an MqttRoute attribute .
internal static MqttRouteTable Create(IEnumerable<Assembly> assemblies)
        {
            var key = new Key(assemblies.OrderBy(a => a.FullName).ToArray());
            if (Cache.TryGetValue(key, out var resolvedComponents))
            {
                return resolvedComponents;
            }
            var asm = assemblies ?? new Assembly[] { Assembly.GetExecutingAssembly() };
            var actions = asm.SelectMany(a => a.GetTypes())
                .Where(type => type.GetCustomAttribute(typeof(MqttControllerAttribute), true) != null)
                .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
                .Where(m => !m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any() && !m.IsDefined(typeof(NonActionAttribute)));
            var routeTable = Create(actions);
            Cache.TryAdd(key, routeTable);
            return routeTable;
        }
internal static MqttRouteTable Create ( IEnumerable < Assembly > assemblies ) { var key = new Key ( assemblies . OrderBy ( a => a . FullName ) . ToArray ( ) ) ; if ( Cache . TryGetValue ( key , out var resolvedComponents ) ) { return resolvedComponents ; } var asm = assemblies ?? new Assembly [ ] { Assembly . GetExecutingAssembly ( ) } ; var actions = asm . SelectMany ( a => a . GetTypes ( ) ) . Where ( type => type . GetCustomAttribute ( typeof ( MqttControllerAttribute ) , true ) != null ) . SelectMany ( type => type . GetMethods ( BindingFlags . Instance | BindingFlags . DeclaredOnly | BindingFlags . Public ) ) . Where ( m => ! m . GetCustomAttributes ( typeof ( System . Runtime . CompilerServices . CompilerGeneratedAttribute ) , true ) . Any ( ) && ! m . IsDefined ( typeof ( NonActionAttribute ) ) ) ; var routeTable = Create ( actions ) ; Cache . TryAdd ( key , routeTable ) ; return routeTable ; }
Given a list of assemblies, find all instances of MqttControllers and wire up routing for them.
Given a list of assemblies find all instances of MqttControllers and wire up routing for them .
None
assemblies
IEnumerable<Assembly>
assembly
Assemblies to scan for routes
Assemblies to scan for routes