I'm building a solution architecture in ASP.NET Core.
I reference repositories in the web project for declare dependency injection in the ConfigureServices()
, is it ok for you?
I think that ideal would be only reference the services project because controllers only should use services but not repositories.
I have these projects:
Web App (ASP.NET Core) - reference all projects.
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddTransient<IEventsService, EventsService>(); services.AddTransient<IEventsRepository, EventsSqlRepository>(); } public class EventsController : Controller { private readonly IEventsService _eventsService; public EventsController(IEventsService eventsService) { _eventsService = eventsService; } }
Business (class library - .NET standard)
Folder IServices IEventsService Folder Services public class EventsService : IEventsService { private readonly IEventsRepository _eventsRepository; public EventsService(IEventsRepository eventsRepository) { _eventsRepository = eventsRepository; } }
IRepository (class library - .NET Standard)
- IEventsRepository
Repository (class library - .NET Standard)
Access to BD using E.F.
public class EventsSqlRepository : BaseRepository, IEventsRepository { }
Utils (class library - .NET Standard)
Entities (class library - .NET Standard)
- Mapped from BD E.F
Thanks very much !