Multiple observers of the ResolveUnregisteredType

Jan 9, 2015 at 9:20 PM
I'm receiving the following exception:
Multiple observers of the ResolveUnregisteredType event are registering a delegate for the same service type: IEnumerable<IAuthorizer<DeleteModel>>. Make sure only one of the registered handlers calls the ResolveUnregisteredType.Register method for a given service type.

I'm using Simple Injector 2.7.0-beta1.

Any help will be appreciated.

Authorizer Registration

private static void RegisterAuthorizers(Container container)
            container.RegisterManyForOpenGeneric(typeof (IAuthorizer<>), container.RegisterAll,

            container.RegisterOpenGeneric(typeof(IAuthorizer<>), typeof(GlobalAdminAuthorizer<>));

            container.RegisterPerWebRequest(() => Thread.CurrentPrincipal);

Other Registrations

 private static void RegisterRequests(Container container)
            container.RegisterManyForOpenGeneric(typeof (IRequestHandler<,>), Assembly.GetExecutingAssembly());

            container.RegisterDecorator(typeof (IRequestHandler<,>), typeof (ValidationHandler<,>));
            container.RegisterDecorator(typeof (IRequestHandler<,>), typeof (AuthorizationHandler<,>));
            container.RegisterDecorator(typeof (IRequestHandler<,>), typeof (UnitOfWorkHandler<,>));
            container.RegisterDecorator(typeof (IRequestHandler<,>), typeof (SqlDebugLoggerHandler<,>));

        private static void RegisterMediator(Container container)
            container.RegisterSingle<IMediator, Mediator>();

        private static void RegisterValidators(Container container)
            container.RegisterManyForOpenGeneric(typeof (IValidator<>), container.RegisterAll,

            container.RegisterSingleOpenGeneric(typeof(IValidator<>), typeof(NullValidator<>));


public interface IAuthorizer<in T> 
        bool Authorize(T instance);

Authorization Handler

public class AuthorizationHandler<TRequest, TResponse> : IRequestHandler<TRequest, TResponse>
        where TRequest : IRequest<TResponse>
        private readonly IRequestHandler<TRequest, TResponse> _inner;
        private readonly IEnumerable<IAuthorizer<TRequest>> _authorizers;

        public AuthorizationHandler(IRequestHandler<TRequest, TResponse> inner,
            IEnumerable<IAuthorizer<TRequest>> authorizers)
            _inner = inner;
            _authorizers = authorizers;

        public TResponse Handle(TRequest message)
            var authorized = _authorizers.Any(authorizer => authorizer.Authorize(message));

            if (!authorized) throw new HttpException(403, "You are not authoirzed to access the requested information");

            return _inner.Handle(message);
Jan 9, 2015 at 9:45 PM
This might be a bug in the beta you are using. Could you post the minimal amount of code that reproduces this issue? And what happens if you roll back to v2.6.1?
Jan 9, 2015 at 10:29 PM
Works when I roll back to 2.6.1.

Out of curiosity, is the beta resolving variants (

The minimal amount of code would be container.Verify();. That's what throws the exception when using the beta.

There is no IAuthorizer for DeleteModel, but there is an IAuthroizer for IInstitutionRequest and IMatrixRequest.
public class DeleteModel : ICommand<Unit>, IInstitutionRequest, IMatrixRequest
        public int MatrixId { get; set; }
        public int InstitutionId { get; set; }
        public string InstName { get; set; }
        public string MatrixDiag { get; set; }
Jan 9, 2015 at 11:46 PM
The beta does resolve variants in collections.

What I mean with the minimum amount of code is a complete compilable registation that I can use to reproduce the issue. Something that I can copy-paste to a unit test for instance and see fail, without having to do trial and error to reproduce the problem. It seems like something thay needs to be fixed, but I'm unsure how easy it is for me to reproduce with your current code.

So I would be very grateful if you would be able to supply me with such reproducable piece of code.
Jan 12, 2015 at 7:58 PM
I'll send you some code in the next couple of days.
Jan 14, 2015 at 8:29 PM
@jbutts, Could you verify if the problem still exists with beta2?
Jan 15, 2015 at 5:03 PM
Sorry, I missed this. I was putting together the code this morning for the beta, but then saw you released 2.7. The issue no longer exists in 2.7. Thanks!
Marked as answer by dot_NET_Junkie on 2/2/2015 at 12:15 PM
Jan 15, 2015 at 5:13 PM
I'm glad to hear.