Thursday, May 20, 2010

Implementing the Bootstrapper for your application

Do you know about Bootstrapper?
If you don't know about it before, I will explain it now. If you used to turn on your computer, you shall see that you only are able to work when your operating system (OS) ready to booting. And underline your computer must do many works for preparing your OS. You can't see those, it only run underline. That is a bootstrapper task. You shall not be care about all task that run under OS, you only need working. Do you agree with me? Yeah! If you agree with me, you understood the jobs that Bootstrapper take it to you.
Now is the time that we come back to software world, How are we able to boot all our tasks in software (include Windows Form & Web)? And why must we run bootstrapper in our application? The second question, one articles can answer for you at here. And the first question I will answer for you after my post end. OK now we shall start to preparing all thing for implementing the Bootstrapper at below:

+ First thing, we must define the interface for the contract in each task:
+ Next, I will implement the abstract class for compositing all functions that I think I can re-use:
+ And I continue to implement sub-class for CommonBootStrapper that I just implemented:
+ Don't confuse about some messy thing in my code. Because I copied it in NMA project, so it have many things (StructureMap, Automapper, Fluent NHibernate,...) in it. But if you follow all post at my blog, I will explain all thing for you. Now continue, we shall implement one class for registering Automapper task when my application started:
Please go to for clear about AutoMapper.
Certainly, you can inplement many tasks for booting, such as setup action filter, add model binder, add custom view engine,...
+ Finally, we shall call it in Global.asax for web or App.xaml in WPF. But in this post I only implement in web:
At here, I used StructureMap for scanning 3 dlls: NMA.Infrastructure.NHibernate, NMA.Application, NMA.Infrastructure.AutoMapper for finding all tasks in my application.
I implemented scanning dll at CoreRegistry.cs, and this is the important function inside this class:
As you see this function will find all class that implemented interface IBootstrapperTask. If you implement it in any other dll, you also show it for Bootstrapper.

* And I answered for you the first question if you read all my post.
In past time, I also suggested this ideas for Deran Schilling and he also implemented very excellent post at here.
OK, I just finished the post about Bootstrapper, if you don't want to implement from scratch, you can use Unity Bootstrapper that mention at here. But it use Prism on WPF.
Finally you can find all my source code on NMA project. Good bye and see you next time!

No comments:

Post a Comment