asp.net - How to introduce application-wide context object? -
i need make several properties accessible application's business layer. ids , common settings. of them valid through request-response lifespan.
web application (asp.net web forms specific) dependency injection set up.
currently properties passed through method parameters directly business layer's services. works not efficient since:
- sometimes parameters' values need passed deeper obscuring readability bit
- some properties should lazy resolved, , should done once per request
- retrieving properties resolved touching database can confusing new developers (there not unified way of doing this)
- some services constructed factory enriches them config parameters
i thinking introducing application context interface, implementation in main project, created on every request. injected services directly making them parametrized automatically , independently (services won't need factory anymore).
is how problem should tackled or maybe there other options?
1 option don't here might bond main particle business layer not perfect example of the clean architecture.
id solution common 1 - inject 'application context' classes. 1 thing careful of though making sure following integration segregation principle (from solid). dont start making classes expect application context instance. instead, design interfaces split application context up, , have classes expect them dependencies. application context need implement interfaces.
this correct way things decouples classes implementation. classes don't care if dependency 1 giant application context, care specific methods implemented it. make code more robust reduce risk of breaking if change implementation of application context later on.
Comments
Post a Comment