windows services - Autofac - How to dispose the root lifetime? -
i'm using autofac ioc container windows service.
i have class connectionmanager
registered singleton (and thus, tied root lifetime scope of autofac).
the ioc container configured , initialized in service's onstart()
method. usual stuff:
private icontainer _container; public void onstart() { var builder = new containerbuilder(); //initialize it... _container = builder.build(); }
i want make sure (singleton) instance of connectionmanager
disposed when service stopped - namely when onstop()
method called. want tell autofac container: "nice meeting you. prepare die."
my question is: how can hands on root lifetime scope in onstop()
method can dispose of it?
the answer staring me in face.
the container root lifetime scope. dispose of container singletons disposed...
public void onstop() { _container.dispose(); }
Comments
Post a Comment