Created
January 20, 2015 21:12
-
-
Save sstorie/2b47c33fc82b0784331f to your computer and use it in GitHub Desktop.
Code to set up the ServiceLocatorProvider for use with MediatR
This file contains hidden or 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
public static void Start() | |
{ | |
var container = StructuremapMvc.StructureMapDependencyScope.Container; | |
// Create a new dependency resolver to use for this request, and save it so we can | |
// set up a service locator provider | |
// | |
var resolver = new StructureMapWebApiDependencyResolver(container); | |
GlobalConfiguration.Configuration.DependencyResolver = resolver; | |
// Now that we have a resolver to use for this request, we can update the | |
// container config to use that for locating services | |
// | |
// Note, we can't put this in the registry because it's not created until | |
// the request happens. | |
// | |
var provider = new ServiceLocatorProvider(() => resolver); | |
container.Configure(cfg => | |
{ | |
cfg.For<ServiceLocatorProvider>().Use(provider); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment