Dear Mr.Hikalkan, May you explain for me about processing flow of Null Object Pattern, like example below: NullEventBus, EventBus When a class using EventBus, it can be initialize with EventBus= NullEventBus.Instance; But i can't understand how actually NullEventBus was replaced by EventBus instead of current NullEventBus. I was refer your document at: <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/EventBus-Domain-Events">http://aspnetboilerplate.com/Pages/Docu ... ain-Events</a> But i still don't understand how this possible, how did you replace NullEventBus with EventBus when method excuting...
- Maybe it was config somewhere?
- So when I create MyDemo and NullMyDemo, how can i implement Null Object pattern like you did?
Thanks and best regards, Toan
1 Answer(s)
-
0
It's done by Castle Windsor by property injection (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dependency-Injection#DocPropertyInjection">http://www.aspnetboilerplate.com/Pages/ ... yInjection</a> and <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dependency-Injection#DocResolveConstAndProp">http://www.aspnetboilerplate.com/Pages/ ... nstAndProp</a>). You can find more info on the web if you want to know details, but I think no need it.
How to make it for your own classes. Easy:
- Define an interface, like IMyDemo.
- Create a class like MyNullDemo which implements IMyDemo but do not register it to DI (do not implement ITransientDependency or others).
- Use property injection wherever you need to IMyDemo.
Then, if user want to override it, he can create RealMyDemo class which implements IMyDemo and registers to DI (can implement ITransientDependency too). Then Castle Windsor will replace MyNullDemo to RealMyDemo automatically.