lucabriguglia / OpenCQRS

.NET Standard framework to create simple and clean design. Advanced features for DDD, CQRS and Event Sourcing.
Apache License 2.0
3 stars 115 forks source link

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

Closed NathalieSpierings closed 2 years ago

NathalieSpierings commented 2 years ago

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

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

lucabriguglia commented 2 years ago

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

lucabriguglia commented 2 years ago

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.

NathalieSpierings commented 2 years ago

Yes this solution ideed worked for me. Thank you

lucabriguglia commented 2 years ago

Glad it worked!