PDA

View Full Version : خطای Lifetime در زمان Migration



mmbguide
جمعه 10 فروردین 1403, 16:32 عصر
سلام دوستان
در زمان Migration کردن EF خطای زیر نمایش داده شده. تا جایی که میشده خطوط را شکستم تا خواندن آن راحت بشه. دلیل رو متوجه نشدم. البته گویا به Lifetime نوع ها گیر داده ولی چطور بفهمم داستان ازکجاست؟

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:
Final_SophieTravelManagement.Domain.Respositories. ITravelerCheckListRepository
Lifetime: Scoped
ImplementationType:
Final_SophieTravelManagement.Infrastructure.EF.Rep ositories.TravelerCheckListRepository':
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbSet`1


[Final_SophieTravelManagement.Domain.Entities.Trave lerCheckList]'
while attempting to activate
'Final_SophieTravelManagement.Infrastructure.EF.Re positories.TravelerCheckListRepository'.)
(Error while validating the service descriptor
'ServiceType:
Type: ICommandHandler`1+Decorated
Lifetime: Scoped
ImplementationType:
Final_SophieTravelManagement.Application.Commands. Handlers.TakeItemHandler':
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbSet`1


[Final_SophieTravelManagement.Domain.Entities.Trave lerCheckList]'
while attempting to activate
'Final_SophieTravelManagement.Infrastructure.EF.Re positories.TravelerCheckListRepository'.)
(Error while validating the service descriptor
'ServiceType:
Type: ICommandHandler`1+Decorated
Lifetime: Scoped
ImplementationType:
Final_SophieTravelManagement.Application.Commands. Handlers.RemoveTravelerItemHandler':
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbSet`1


[Final_SophieTravelManagement.Domain.Entities.Trave lerCheckList]' while attempting to activate 'Final_SophieTravelManagement.Infrastructure.EF.Re positories.TravelerCheckListRepository'.) (Error while validating the service descriptor 'ServiceType: Type: ICommandHandler`1+Decorated Lifetime: Scoped ImplementationType: Final_SophieTravelManagement.Application.Commands. Handlers.RemoveTravelerCheckListHandler': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbSet`1


[Final_SophieTravelManagement.Domain.Entities.Trave lerCheckList]' while attempting to activate 'Final_SophieTravelManagement.Infrastructure.EF.Re positories.TravelerCheckListRepository'.) (Error while validating the service descriptor 'ServiceType: Type: ICommandHandler`1+Decorated Lifetime: Scoped ImplementationType: Final_SophieTravelManagement.Application.Commands. Handlers.CreateTravelerCheckListWithItemsHandler': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbSet`1


[Final_SophieTravelManagement.Domain.Entities.Trave lerCheckList]'
while attempting to activate
'Final_SophieTravelManagement.Infrastructure.EF.Re positories.TravelerCheckListRepository'.)
(Error while validating the service descriptor
'ServiceType:
Type: ICommandHandler`1+Decorated
Lifetime: Scoped
ImplementationType:
Final_SophieTravelManagement.Application.Commands. Handlers.AddTravelerItemHandler':
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbSet`1


[Final_SophieTravelManagement.Domain.Entities.Trave lerCheckList]'
while attempting to activate
'Final_SophieTravelManagement.Infrastructure.EF.Re positories.TravelerCheckListRepository'.)

mmbguide
چهارشنبه 15 فروردین 1403, 21:24 عصر
سلام دوستان
مشکل حل شد. دلیل این کار دقیق متوجه نشدم چیه ولی فکر میکنم بدلیل آنکه از لایه API تا DbContext بدلیل پیاده سازی معماری تمیز و... از کلاس های Abstract و... زیاد استفاده شده بود احتمالا نمیشد DbContextOption را به متد سازنده در کلاس ApplicationDbContext ارسال کرد. بنابراین در جایی که ApplicationDbContext ایجاد شده بود یک کلاس ایجاد کردم و رابط IDesignTimeDbContextFactory را پیاده سازی کردم و مشکل حل شد. Migration انجام شد و Database هم ساخته شد.

https://github.com/CesSolutions/CleanArchitecture_CQRS_DDD