为什么我得到Microsoft.Practices.Unity.ResolutionFailedException

时间:2018-01-04 11:12:09

标签: asp.net

 Message=Resolution of the dependency failed, type = "Registration.Handlers.BookItemHandler", name = "(none)".
Exception occurred while: Calling constructor Infrastructure.Sql.EventSourcing.SqlEventSourcedRepository`1[[Registration.BookItem, Registration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](Infrastructure.Messaging.IEventBus eventBus, Infrastructure.Serialization.ITextSerializer serializer, System.Func`1[[Infrastructure.Sql.EventSourcing.EventStoreDbContext, Infrastructure.Sql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] contextFactory).

以下是代码:

    container.RegisterType<ICommandHandler, BookItemHandler>("BookItemHandler");

public class BookItemHandler :
        ICommandHandler<CreateBookItem>,
        IEventHandler<ItemCreated>
    {
        private readonly IEventSourcedRepository<BookItem> repository;

        public BookItemHandler(IEventSourcedRepository<BookItem> repository)
        {
            this.repository = repository;
        }
        public void Handle(CreateBookItem command)
        {
            //Persist the Share
            //BookItem bookItem = this.repository.Get(command.Id);            
            //this.repository.Save(bookItem, command.Id.ToString());                    
        }

        public void Handle(ItemCreated @event)
        {
            throw new NotImplementedException();
        }
    }

public SqlEventSourcedRepository(IEventBus eventBus, ITextSerializer serializer, Func<EventStoreDbContext> contextFactory)
        {
            this.eventBus = eventBus;
            this.serializer = serializer;
            this.contextFactory = contextFactory;

            // TODO: could be replaced with a compiled lambda
            var constructor = typeof(T).GetConstructor(new[] { typeof(Guid), typeof(IEnumerable<IVersionedEvent>) });
            if (constructor == null)
            {
                throw new InvalidCastException("Type T must have a constructor with the following signature: .ctor(Guid, IEnumerable<IVersionedEvent>)");
            }
            this.entityFactory = (id, events) => (T)constructor.Invoke(new object[] { id, events });
        }

0 个答案:

没有答案