lundi 24 mai 2021

Services registered with Scrutor don't have implementation instance

I was trying to get it to work for about 6 hours and I don't know what is wrong. Anyway:

I want to register all domain events listeners from application and call given methods if any of the domain events occurs.

Startup:

        services.Scan(scan => scan
            .FromAssemblies(AppDomain.CurrentDomain.GetAssemblies())
            .AddClasses(c => c.AssignableTo(typeof(IDomainEventListener<>)))
            .AsImplementedInterfaces()
            .WithSingletonLifetime());

Domain event bus:

public void Raise<T>(T args) where T : IDomainEvent
    {
        _serviceCollection.Where(s => s.ServiceType == typeof(IDomainEventListener<T>))
            .ToList()
            .ForEach(s =>
            {
                var descriptor = s;
            });
    }

What I mean by "Implementation instance" is that I can't get object which should be assigned to given IDomainEventListener. (s is ServiceDescriptor from ForEach given in code snippet above).

enter image description here

So my question is: What I'm doing wrong or how can I get object instance which implements interface of given type?





Aucun commentaire:

Enregistrer un commentaire