private void BuildApplicationObjectGraph(ContainerBuilder builder, params Assembly[] assemblies)
{
// Instantiate and store all controllers...
// These must be executed in the order of dependency. For example the RulesController requires a NewRuleController so the NewRuleController must be instantiated first.
IContainer container = builder.Build();
Logger = container.Resolve<ILogger>();
foreach (Assembly assembly in assemblies)
{
var requiredPropertyInjections = DefaultIoCRegistrations.ProcessPropertyInjection(assembly);
foreach (PropertyInjectionDependencyRequirement requirement in requiredPropertyInjections)
{
// Some reasonably awkard Autofac usage here to allow testibility. (Extension methods aren't easy to test)
IComponentRegistration registration;
bool success = container.ComponentRegistry.TryGetRegistration(new TypedService(requirement.DependencyRequired), out registration);
if (success)
{
object dependency = container.ResolveComponent(registration, Enumerable.Empty<Parameter>());
requirement.PropertyInjectionAssignment(dependency);
}
}
}
// Kick it off
ConstructUiContext(container);
this.disposables.AddIfSomething(container.Resolve<ICredentialStore>() as IDisposable);
ShellController = container.Resolve<ShellController>();
ShellWindow = new ShellWindow { DataContext = ShellController };
}