fullstackhero / dotnet-starter-kit

Production Grade Cloud-Ready .NET 8 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.

Home Page:https://fullstackhero.net/dotnet-webapi-boilerplate/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removing AddBackgroundJobs or AddNotifications from registering in DI service container fails to run migrations

devdgupta opened this issue · comments

Describe the bug
Since I don't want the Notification(SignalR) and BackgroundJobs(Hangfire) service at present in my application , so I removed these from the DI service container and Middleware pipeline but after removing this application runs perfectly, however failing to execute the migrations command.

To Reproduce
Steps to reproduce the behavior:

  1. remove AddBackgroundJobs and AddNotifications from DI service container present in method AddInfrastructure
  2. remove UseHangfireDashboard and MapNotifications from Middleware pipeline
  3. Add any new POCO model class
  4. run migration command

Expected behavior
Migration must run without any errors.

Stack Trace
Stack Trace :

dotnet ef migrations add XYZAdded --project .././Migrators/Migrators.MSSQL/ --context ApplicationDbContext -o Migrations/Application
Build started...
Build succeeded.
[10:55:16 INF] Server Booting Up...
[10:55:18 FTL] Unhandled exception
System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Dcent.App.Application.Catalog.Brands.IBrandGeneratorJob Lifetime: Scoped ImplementationType: Dcent.App.Infrastructure.Catalog.BrandGeneratorJob': Unable to resolve service for type 'Hangfire.Console.Extensions.IProgressBarFactory' while attempting to activate 'Dcent.App.Infrastructure.Catalog.BrandGeneratorJob'.)
---> System.InvalidOperationException: Error while validating the service descriptor 'ServiceType: Dcent.App.Application.Catalog.Brands.IBrandGeneratorJob Lifetime: Scoped ImplementationType: Dcent.App.Infrastructure.Catalog.BrandGeneratorJob': Unable to resolve service for type 'Hangfire.Console.Extensions.IProgressBarFactory' while attempting to activate 'Dcent.App.Infrastructure.Catalog.BrandGeneratorJob'.
---> System.InvalidOperationException: Unable to resolve service for type 'Hangfire.Console.Extensions.IProgressBarFactory' while attempting to activate 'Dcent.App.Infrastructure.Catalog.BrandGeneratorJob'.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceDescriptor serviceDescriptor, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.ValidateService(ServiceDescriptor descriptor)
--- End of inner exception stack trace ---
at Microsoft.Extensions.DependencyInjection.ServiceProvider.ValidateService(ServiceDescriptor descriptor)
at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection1 serviceDescriptors, ServiceProviderOptions options) --- End of inner exception stack trace --- at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection1 serviceDescriptors, ServiceProviderOptions options)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
at Program.

$(String[] args) in \src\Host\Program.cs:line 23
[10:55:18 INF] Server Shutting down...
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: The entry point exited without ever building an IHost.
Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

Additional context
If I do not remove any service then getting Host was aborted error but at that migration executes successfully.

duplicate issue