c# - Topshelf windows service, Structure map - > achieve per request object lifecycle for timer elapsed event -
i have windows service application hosted topshelf. initializing structure map container once, when service started. have timer, scheduled tasks triggered on each timer elapsed event. have "per request " object creation have same instances of initialized objects durring 1 timer tick, , dispose them when job finished. on next tick of timer have new object instances (e.g. objects dbcontext ef.. ). how can achieve structure map possible?
i think you're looking nested container:
http://structuremap.github.io/the-container/nested-containers/
the naive implementation pass application's container elapsed
event handler, call getnestedcontainer()
on it, , dispose
of nested container before handler exits.
Comments
Post a Comment