I am creating a project with ASP.NET Core 3.1 and was writing the BusinessManager layers to connect to database. It was going without a hitch but I come to roadblock when I added the service for the blog table for the blogs I will add.
services.AddScoped<IBlogBusinessManager, BlogBusinessManager>();
This is how I am trying to add the service. But while I starting the project this error appears;
AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: MyBlog.BusinessManagers.Interfaces.IBlogBusinessManager Lifetime: Scoped ImplementationType: MyBlog.BusinessManagers.BlogBusinessManager': Unable to resolve service for type 'MyBlog.Service.Interfaces.IBlogService' while attempting to activate 'MyBlog.BusinessManagers.BlogBusinessManager'.)
Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable serviceDescriptors, IServiceProviderEngine engine, ServiceProviderOptions options)
This is the BlogService class mentioned in the error:
public class BlogService : IBlogService
{
private readonly ApplicationDbContext _applicationDbContext;
public BlogService(ApplicationDbContext applicationDbContext)
{
this._applicationDbContext = applicationDbContext;
}
public async Task<Blog> Add(Blog blog)
{
_applicationDbContext.Add(blog);
await _applicationDbContext.SaveChangesAsync();
return blog;
}
}
And this is the interface I use
public interface IBlogService
{
Task<Blog> Add(Blog blog);
}
Is there any solution for this error?