Using multiple DbContexts with a generic repository and unit of work

前端 未结 2 775
孤城傲影
孤城傲影 2021-01-31 06:59

My application is getting larger and so far I have a single MyDbContext which has all the tables I need in my application. I wish (for the sake of overview) to spli

2条回答
  •  渐次进展
    2021-01-31 07:16

    Your unit of work interface is not generic but the implementation is. The easiest way to clean up this would be to decide and follow the same convention.

    For example, make your interface generic also. This way you could register three different interfaces (the same interface with three different generic parameters) to three different implementations:

     container.Bind( typeof> ).To( typeof> );
     ...
    

    And yes, this is a good idea to inject your unit of works into controllers / services.

提交回复
热议问题