dependency injection - Autofac MVVM - Lifetime -
are there examples of using autofac in mvvm application? i'm not sure how 1 control lifetimes , disposal of objects in mvvm environment.
i understand can create lifetime , resolve beneath it, seems more service locator pattern ioc pattern.
i don't have public example, have done in silverlight applications.
i used silverlight navigation framework organize top level of content. when frame navigated new page, created lifetime scope in resolved page's root view model, associated page through attribute:
[viewmodel(typeof(ordersviewmodel))] public class ordersview : page
when frame navigated different page, disposed lifetime scope before creating next one.
the same pattern applies opening dialogs. each dialog gets own lifetime scope , view model. when closes, lifetime scope gets disposed.
there situations don't fall neatly along these boundaries. need more granularity , can go deeper lifetime scopes using contextual scopes. these situations one-offs , involve glue begin lifetime scopes.
i find helpful think in terms of units of work: commit changes @ end of each lifetime scope. makes extent of set of data natural lifetime scope.
Comments
Post a Comment