.net - Resource management in decoupled applications -


i'm building decoupled application using unity, prism.

problem worry resource management in services. easier explain in example: imagine w have interface idataretriever provides sort of data. implementation registered instance. implementation of interface based on anything: files (filedataretriever), sql server (sqlserverdataretriever), simple dictionary. concrete implementation use configured (possibly via configuration file, doesn't matter).

once application finished working, depending on service implementation should release resources (e.g. close connections, close files etc) or not (e.g. when using dictionary), work decoupled abstractions don't know both things: 1. when resources should released 2. whether concrete implementation needs resource deallocation or not.

i think of scenario when bootstrapper implement idisposable, , check each service idisposable implementation, , call dispose modules (which mean modules have implement idisposable well) doesn't correct way of handling such things (too complex)?

you may decide you're able (and in fact it's preferable) release resources data retriever has finished operation. in case, releasing of resources implicit in call getdata or equivalent method part of abstraction client code uses.

alternatively, if don't wish release resources until point until after you've retrieved data, need expose release or equivalent method on abstraction. messy forcing services implement method if don't require it, place method on separate interface, , implement appropriate services.

you client code check injected service implements interface @ appropriate time, , invoke release method if appropriate.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -