Base solution for your next web application
Open Closed

Question about processing flow of Null Object Pattern #896


User avatar
0
nmtoan07 created

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...

  1. Maybe it was config somewhere?
  2. 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)
  • User Avatar
    0
    hikalkan created
    Support Team

    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:

    1. Define an interface, like IMyDemo.
    2. Create a class like MyNullDemo which implements IMyDemo but do not register it to DI (do not implement ITransientDependency or others).
    3. 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.