c# - Best way to have two versions of a dependency per application part using Unity? -
i using unity , mvc5 .net 4.6
- i have data service.
- it depends on repository.
- which in turn depends on connection.
the connection requires username/token make connection or user/application guid make connection data source.
both mvc controllers , web api use data service, data service should not care how being used.
- when used mvc controller username , token is in claim.
- when connected application uses api must pass in user guid , application gui.
when inject data service controller unity news dependencies, data service repository injected , repository connection injected.
the question best pattern getting variables user connection current controller?
you can configure 2 different containers, 1 mvc , 1 web api. or, if have service needs shared between mvc , web api (e.g. singleton service), can create 2 child containers (call container.createchildcontainer()) of container have , register connection in child containers. can make distinction between connection used mvc , web api.
Comments
Post a Comment