简体   繁体   中英

eventflow cqrs Autofac registration of ReadModelLocator throws exception

I'm trying to use EventFlow CQRS framework in a AspNetCore 2.1 webapi. Everything is working fine but after registration of a ReadModelLocator, the code throws an exception:

**Exception has occurred: CLR/System.AggregateException**
An exception of type 'System.AggregateException' occurred in EventFlow.dll but was not handled in user code: 'An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DomainEventPublisher (ReflectionActivator), Services = [EventFlow.Subscribers.DomainEventPublisher], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IReadStoreManager[] (DelegateActivator), Services = [System.Collections.Generic.IEnumerable`1[[EventFlow.ReadStores.IReadStoreManager, EventFlow, Version=0.67.3697.0, Culture=neutral, PublicKeyToken=null]]], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IReadStoreManager (DelegateActivator), Services = [EventFlow.ReadStores.IReadStoreManager], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = MultipleAggregateReadStoreManager`3 (ReflectionActivator), Services = [EventFlow.ReadStores.MultipleAggregateReadStoreManager`3[[EventFlow.ReadStores.InMemory.IInMemoryReadStore`1[[querymodel.endpoint.EndpointModel, query-model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], EventFlow, Version=0.67.3697.0, Culture=neutral, PublicKeyToken=null],[querymodel.endpoint.EndpointModel, query-model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[querymodel.endpoint.EndpointByCodeLocator, query-model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'EventFlow.ReadStores.MultipleAggregateReadStoreManager`3[EventFlow.ReadStores.InMemory.IInMemoryReadStore`1[querymodel.endpoint.EndpointModel],querymodel.endpoint.EndpointModel,querymodel.endpoint.EndpointByCodeLocator]' can be invoked with the available services and parameters:
Cannot resolve parameter 'querymodel.endpoint.EndpointByCodeLocator readModelLocator' of constructor 'Void .ctor(EventFlow.Logs.ILog, EventFlow.Configuration.IResolver, EventFlow.ReadStores.InMemory.IInMemoryReadStore`1[querymodel.endpoint.EndpointModel], EventFlow.ReadStores.IReadModelDomainEventApplier, querymodel.endpoint.EndpointByCodeLocator, EventFlow.ReadStores.IReadModelFactory`1[querymodel.endpoint.EndpointModel])'. (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.), An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IDomainEventPublisher (DelegateActivator), Services = [EventFlow.Subscribers.IDomainEventPublisher], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = DomainEventPublisher (ReflectionActivator), Services = [EventFlow.Subscribers.DomainEventPublisher], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IReadStoreManager[] (DelegateActivator), Services = [System.Collections.Generic.IEnumerable`1[[EventFlow.ReadStores.IReadStoreManager, EventFlow, Version=0.67.3697.0, Culture=neutral, PublicKeyToken=null]]], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IReadStoreManager (DelegateActivator), Services = [EventFlow.ReadStores.IReadStoreManager], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = MultipleAggregateReadStoreManager`3 (ReflectionActivator), Services = [EventFlow.ReadStores.MultipleAggregateReadStoreManager`3[[EventFlow.ReadStores.InMemory.IInMemoryReadStore`1[[querymodel.endpoint.EndpointModel, query-model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], EventFlow, Version=0.67.3697.0, Culture=neutral, PublicKeyToken=null],[querymodel.endpoint.EndpointModel, query-model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[querymodel.endpoint.EndpointByCodeLocator, query-model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'EventFlow.ReadStores.MultipleAggregateReadStoreManager`3[EventFlow.ReadStores.InMemory.IInMemoryReadStore`1[querymodel.endpoint.EndpointModel],querymodel.endpoint.EndpointModel,querymodel.endpoint.EndpointByCodeLocator]' can be invoked with the available services and parameters:
Cannot resolve parameter 'querymodel.endpoint.EndpointByCodeLocator readModelLocator' of constructor 'Void .ctor(EventFlow.Logs.ILog, EventFlow.Configuration.IResolver, EventFlow.ReadStores.InMemory.IInMemoryReadStore`1[querymodel.endpoint.EndpointModel], EventFlow.ReadStores.IReadModelDomainEventApplier, querymodel.endpoint.EndpointByCodeLocator, EventFlow.ReadStores.IReadModelFactory`1[querymodel.endpoint.EndpointModel])'

I've registered all components as described in the example:

var builder = new ContainerBuilder();
builder.Populate(services);
var container = EventFlowOptions.New
  .UseAutofacContainerBuilder(builder)
  .UseConsoleLog()
  .UseFilesEventStore(FilesEventStoreConfiguration.Create("./evt-store"))
  .AddDefaults(typeof(Endpoint).Assembly)
  .AddDefaults(typeof(EndpointModel).Assembly)
  .AddDefaults(typeof(CreateEndpointCommand).Assembly)
  .UseInMemoryReadStoreFor<EndpointModel, EndpointByCodeLocator>()
  .CreateContainer();

Any ideas? THX!

The Endpoint and EndpointByCodeLocator class have been implemented like this

public class Endpoint : AggregateRoot<Endpoint, EndpointId>
{
    public Endpoint(EndpointId id) : base(id){}
    public string Code { get; private set; }
    public void Initialize(string code, string source)
    {
        Emit(new EndpointInitializedEvent(code,source));
    }
    public void Apply(EndpointInitializedEvent evt)
    {
        Code = evt.Code;
    }
}

public class EndpointByCodeLocator : IReadModelLocator
{
    public IEnumerable<string> GetReadModelIds(IDomainEvent evt)
    {
        var endpointInitializedEvent = evt as IDomainEvent<Endpoint, EndpointId, EndpointInitializedEvent>;
        if (endpointInitializedEvent == null)
            yield break;
        else
            yield return endpointInitializedEvent.AggregateEvent.Code;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM