elsa-workflows / elsa-workflows/elsa-core
System.InvalidOperationException: Cannot resolve scoped service IEnumerable<IDbContextOptionsConfiguration<ManagementElsaDbContext>>
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
## Description
I created an Elsa Server project based on Elsa-workflow, using Entity Framework Core and SQLite, but an error occurred when starting it as follows:
```
Unhandled exception. System.InvalidOperationException: Cannot resolve scoped service 'System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.Infrastructure.IDbContextOptionsConfiguration`1[Elsa.EntityFrameworkCore.Modules.Management.ManagementElsaDbContext]]' from root provider.
```
## Steps to Reproduce
My code is in the following repository: https://github.com/vitamin-d3/ElsaWebServer
just type dotnet run , and it will fail.
The main code content is as follows:
```
using Elsa.EntityFrameworkCore.Extensions;
using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.Extensions;
using Elsa.Features.Services;
using Elsa.Workflows.LogPersistence;
namespace ElsaWebServer;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddElsa(AddElsa);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.UseWorkflowsApi();
//// Elsa HTTP Endpoint activities.
app.UseWorkflows();
app.Run();
}
private static void AddElsa(IModule elsa)
{
elsa.UseWorkflows(workflows =>
{
})
.UseWorkflowManagement(management =>
{
management.UseEntityFrameworkCore(ef =>
{
ef.UseContextPooling = true;
ef.UseSqlite(sp => "Data Source=workflow.db");
ef.RunMigrations = true;
});
management.SetDefaultLogPersistenceMode(LogPersistenceMode.Inherit);
management.UseReadOnlyMode(false);
})
.UseWorkflowRuntime(runtime =>
{
runtime.UseEntityFrameworkCore(ef =>
{
ef.UseContextPooling = true;
ef.UseSqlite(sp => "Data Source=workflow.db");
ef.RunMigrations = true;
});
})
.UseWorkflowsApi(api =>
{
api.AddFastEndpointsAssembly();
});
elsa.AddFastEndpointsAssembly();
}
}
```
## Expected Behavior
It should run as a elsa server.
## Actual Behavior
Error occurs.
## Screenshots
## Environment
- **Elsa Package Version**: 3.3.5
- **Operating System**: Windows 11
- **Browser and Version**: MS Edge latest Version
## Log Output
```
Unhandled exception. System.InvalidOperationException: Cannot resolve scoped service 'System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.Infrastructure.IDbContextOptionsConfiguration`1[Elsa.EntityFrameworkCore.Modules.Management.ManagementElsaDbContext]]' from root provider.
```
## Troubleshooting Attempts
## Additional Context
## Related Issues
Contributor guide
Assessment
This issue has not been assessed yet.