lundi 19 octobre 2020

Using Entity Framework and .net core web API on DDD

I'm using .net core and EF. I follow the DDD approach. That's my question what is a good way or how I can handle it. Within the startup.cs I added a new service

services.AddDbContext<RMDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("KplDbConnection")));

Within the constructor of the controller I defined a parameter, so I can use it

        public TestController(ILogger<TestController> logger, IOptions<WebAppSettings> configuration, RMDbContext context)
        {
            _logger = logger ?? NullLogger<TestController>.Instance;
            _configuration = configuration;
            _context = context;
        }

But now my question. Now I want use the DB connection later in code. The controller will call a command class, which is using a repository class. In that repository class I want to use the DB connection. What is a good approach to do that?

Thanks!

Aucun commentaire:

Enregistrer un commentaire