Reputation: 541
I m reading Prism library by microsoft. I just dont understand ConfigureContainer()
.
The code in shell application like this:
internal class JamSoftBootstrapper : UnityBootstrapper
{
protected override IModuleEnumerator GetModuleEnumerator()
{
return new DirectoryLookupModuleEnumerator("Modules");
}
protected override void ConfigureContainer()
{
Container.RegisterType<IShellView, Shell>();
base.ConfigureContainer();
}
protected override DependencyObject CreateShell()
{
ShellPresenter presenter = Container.Resolve<ShellPresenter>();
IShellView view = presenter.View;
view.ShowView();
return view as DependencyObject;
}
}
public interface IShellView
{
void ShowView();
}
public class ShellPresenter
{
public IShellView View { get; private set; }
public ShellPresenter(IShellView view)
{
View = view;
}
}
I want to understand why I register IShellView,Shell in ConfigureContainer(). Whats going on behind sceens?
Upvotes: 0
Views: 2027
Reputation: 256
I've registered to give you answer :). ConfigureContainer
is just method from abstract class UnityBootstrapper
where you can register all Prism
services (ModuleManager
, RegionManager
, EventAggregator
). You can make your custom Bootstrapper
class, where you can manage your dependency. In your case, every time when you in your code ask for IShellView
, you'll get instance of Shell
.
I recommend you this book. It's free.
Upvotes: 2
Reputation: 81233
UnityBootstrapper
provided by PRISM internally uses UnityContainer to resolve dependency for your registered objects. You can configure your custom objects with it like you are doing in sample.
In your sample, you registered Shell
with instance IShellView
.
Container.RegisterType<IShellView, Shell>();
So whenever you ask container to get you object for IShellView, it will give you an instance of Shell object.
IShellView shellObject = Container.Resolve<IShellView>();
So, ConfigureContainer
gives you support to register your objects with it's container.
Quote from MSDN link:
Configures the IUnityContainer. May be overwritten in a derived class to add specific type mappings required by the application.
Also, you can read more about it here - Managing Dependencies Between Components Using the Prism Library 5.0 for WPF.
Upvotes: 1