Rebus.Autofac/Autofac/AutofacHandlerActivator.cs
/// <summary>
/// Resolves all handlers for the given <typeparamref name="TMessage"/> message type
/// </summary>
Resolves all handlers for the given  message type
Resolves all handlers for the given message type
public async Task<IEnumerable<IHandleMessages<TMessage>>> GetHandlers<TMessage>(TMessage message, ITransactionContext transactionContext)
        {
            ILifetimeScope CreateLifetimeScope()
            {
                var scope = _container.BeginLifetimeScope();
                transactionContext.OnDisposed(ctx => scope.Dispose());
                return scope;
            }
            var lifetimeScope = transactionContext.GetOrAdd("current-autofac-lifetime-scope", CreateLifetimeScope);
            var resolver = _resolvers.GetOrAdd(typeof(TMessage),
                messageType =>
                {
                    if (messageType.IsAssignableTo(typeof(IFailed<>)))
                    {
                        var containedMessageType = messageType.GetGenericTypeParameters(typeof(IFailed<>)).Single();
                        var additionalTypesToResolveHandlersFor = containedMessageType.GetBaseTypes(includeSelf: false);
                        var typesToResolve = new[] { containedMessageType }
                            .Concat(additionalTypesToResolveHandlersFor)
                            .Select(type => typeof(IEnumerable<>).MakeGenericType(typeof(IHandleMessages<>).MakeGenericType(typeof(IFailed<>).MakeGenericType(type))))
                            .ToArray();
                        return scope =>
                        {
                            var handlers = new List<IHandleMessages<TMessage>>();
                            foreach (var type in typesToResolve)
                            {
                                handlers.AddRange((IEnumerable<IHandleMessages<TMessage>>)scope.Resolve(type));
                            }
                            return handlers;
                        };
                    }
                    return scope => scope.Resolve<IEnumerable<IHandleMessages<TMessage>>>();
                });
            return (IEnumerable<IHandleMessages<TMessage>>)resolver(lifetimeScope);
        }
public async Task < IEnumerable < IHandleMessages < TMessage > > > GetHandlers < TMessage > ( TMessage message , ITransactionContext transactionContext ) { ILifetimeScope CreateLifetimeScope ( ) { var scope = _container . BeginLifetimeScope ( ) ; transactionContext . OnDisposed ( ctx => scope . Dispose ( ) ) ; return scope ; } var lifetimeScope = transactionContext . GetOrAdd ( " " , CreateLifetimeScope ) ; var resolver = _resolvers . GetOrAdd ( typeof ( TMessage ) , messageType => { if ( messageType . IsAssignableTo ( typeof ( IFailed < > ) ) ) { var containedMessageType = messageType . GetGenericTypeParameters ( typeof ( IFailed < > ) ) . Single ( ) ; var additionalTypesToResolveHandlersFor = containedMessageType . GetBaseTypes ( includeSelf : false ) ; var typesToResolve = new [ ] { containedMessageType } . Concat ( additionalTypesToResolveHandlersFor ) . Select ( type => typeof ( IEnumerable < > ) . MakeGenericType ( typeof ( IHandleMessages < > ) . MakeGenericType ( typeof ( IFailed < > ) . MakeGenericType ( type ) ) ) ) . ToArray ( ) ; return scope => { var handlers = new List < IHandleMessages < TMessage > > ( ) ; foreach ( var type in typesToResolve ) { handlers . AddRange ( ( IEnumerable < IHandleMessages < TMessage > > ) scope . Resolve ( type ) ) ; } return handlers ; } ; } return scope => scope . Resolve < IEnumerable < IHandleMessages < TMessage > > > ( ) ; } ) ; return ( IEnumerable < IHandleMessages < TMessage > > ) resolver ( lifetimeScope ) ; }
Resolves all handlers for the given  message type
Resolves all handlers for the given message type
message
TMessage
transactionContext
ITransactionContext