lucabriguglia/OpenCQRS

Following wiki, always getting 'Some services are not able to be constructed

Closed this issue · 4 comments

I have created a .NET Core 6.0 Webapplication and installed the following packages:

  • OpenCqrs (6.5.0)
  • OpenCqrs.Caching.Memory (6.5.0)
  • OpenCqrs.Store.EF (6.5.0)
  • OpenCqrs.Store.EF.SqlServer (6.5.0)
  • OpenCqrs.UI (6.5.0)
  • OpenCqrs.Validation.FluentValidation(6.5.0)

I have followed the wiki Configuration as followed:

In my .net core 6 web project in de Program.cs i have the following configuration:

var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");

builder.Services.AddOpenCqrs(options =>
    {
        options.PublishEvents = true;
        options.SaveCommandData = true;
    }, typeof(CreateOrganisation))
    .AddSqlServerStore(options => { options.ConnectionString = connectionString; })
    .AddEFStore()
    .AddFluentValidation(options => { options.ValidateAllCommands = false; })
    .AddMemoryCache(options => { options.DefaultCacheTime = 60; })
    .AddUI();

var app = builder.Build();

app.UseOpenCqrs().EnsureDomainDbCreated();

When i use migrations update-database i got the following errors:

An error occurred while accessing the Microsoft.Extensions.Hosting services.
Continuing without the application service provider.
Error: Some services are not able to be constructed 
(Error while validating the service descriptor 'ServiceType: OpenCqrs.Extensions.IOpenCqrsAppBuilder Lifetime: Transient ImplementationType: OpenCqrs.Extensions.OpenCqrsAppBuilder': Unable to resolve service for type 'Microsoft.AspNetCore.Builder.IApplicationBuilder' while attempting to activate 'OpenCqrs.Extensions.OpenCqrsAppBuilder'.)
(Error while validating the service descriptor 'ServiceType: OpenCqrs.Extensions.IOpenCqrsServiceBuilder Lifetime: Transient ImplementationType: OpenCqrs.Extensions.OpenCqrsServiceBuilder': Unable to resolve service for type 'Microsoft.Extensions.DependencyInjection.IServiceCollection' while attempting to activate 'OpenCqrs.Extensions.OpenCqrsServiceBuilder'.) 
(Error while validating the service descriptor 'ServiceType: System.Runtime.Serialization.ISerializable Lifetime: Transient ImplementationType: OpenCqrs.Exceptions.ConcurrencyException': Unable to resolve service for type 'System.Guid' while attempting to activate 'OpenCqrs.Exceptions.ConcurrencyException'.)
(Error while validating the service descriptor 'ServiceType: System.Runtime.Serialization.ISerializable Lifetime: Transient ImplementationType: OpenCqrs.Exceptions.HandlerNotFoundException': Unable to resolve service for type 'System.Type' while attempting to activate 'OpenCqrs.Exceptions.HandlerNotFoundException'.)
(Error while validating the service descriptor 'ServiceType: System.Runtime.Serialization.ISerializable Lifetime: Transient ImplementationType: OpenCqrs.Exceptions.QueryException': Unable to resolve service for type 'System.String' while attempting to activate 'OpenCqrs.Exceptions.QueryException'.) 
(Error while validating the service descriptor 'ServiceType: System.Runtime.Serialization.ISerializable Lifetime: Transient ImplementationType: OpenCqrs.Exceptions.ValidationException': Unable to resolve service for type 'System.String' while attempting to activate 'OpenCqrs.Exceptions.ValidationException'.)

What am i missing here?
Thank you for the help

Hi @NathalieSpierings, I'll try to reproduce it.

Okay, the reason is explained here.

For the time being it's possible to use OpenCQRS in .NET 6 by using the old pattern with Startup.cs.

Yes this solution ideed worked for me.
Thank you

Glad it worked!