.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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -