Created
July 22, 2011 02:28
-
-
Save JakeGinnivan/1098765 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//In app.xaml.cs | |
public void AppStartup() | |
{ | |
var containerBuilder = new ContainerBuilder(); | |
containerBuilder | |
.RegisterAssembly(typeof(App).Assembly) | |
.AssignableTo<IView>() | |
.AsImplementedInterfaces(); | |
var container = containerBuilder.Build(); | |
container.Resolve<IUIService>().ShowDialog(container.Resolve<IMainView>()); | |
//this should be the only place the container is ever referenced | |
} | |
public interface IView {} | |
public interface IMyView {} | |
public partial class MyView : IMyView | |
{ | |
public MyView(MyViewModel viewModel) | |
{ | |
DataContext = viewModel; | |
InitaliseComponent(); | |
} | |
} | |
public class MyViewModel : ViewModelBase | |
{ | |
public MyViewModel() | |
{ | |
//Could throw here if not in design time | |
} | |
public MyViewModel(ISomeDependency someDependency) | |
{ | |
_someDependency = someDependency; | |
} | |
} | |
//The only place we use ServiceLocator.Current is in our EventAggregator to resolve handlers for a particular event. i.e | |
Type handlerInterface = typeof(IHandleDomainEvent<>).MakeGenericType(domainEvent.GetType()); | |
IEnumerable<object> allhandlers = ServiceLocator.Current.GetAllInstances(handlerInterface); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment