Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- container.Release(obj);
- obj.Dispose();
- container.Release(obj);
- using(ISomeService service = container.Resolve<ISomeService>())
- {
- // Do stuff here
- // service.Dispose is automatically called
- }
- var container = new WindsorContainer();
- container.AddComponentWithLifestyle<MyDisposable>(Castle.Core.LifestyleType.Singleton);
- var obj = container.Resolve<MyDisposable>(); // Create a new instance of MyDisposable
- obj.DoSomething();
- var obj2 = container.Resolve<MyDisposable>(); // Returns the same instance as obj
- obj2.DoSomething();
- container.Dispose(); // Will call the Disposable method of obj
- // Now the components need to be added back in
- container.AddComponentWithLifestyle<MyDisposable>(Castle.Core.LifestyleType.Singleton);
- var obj3 = container.Resolve<MyDisposable>(); // Create a new instance of MyDisposable
Add Comment
Please, Sign In to add comment