Created
June 10, 2011 18:30
-
-
Save bsatrom/1019434 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
public class StructureMapContainer : IDependencyResolver | |
{ | |
static IContainer _container; | |
public StructureMapContainer(IContainer container) | |
{ | |
_container = container; | |
_container.Configure(x => x.Scan(y => | |
{ | |
y.AssembliesFromApplicationBaseDirectory(); | |
y.WithDefaultConventions(); | |
y.AddAllTypesOf<IController>() | |
.NameBy(z => z.Name.Replace("Controller", "") | |
.ToLower()); | |
y.LookForRegistries(); | |
})); | |
} | |
public object GetService(Type serviceType) | |
{ | |
return _container.TryGetInstance(serviceType); | |
} | |
public IEnumerable<object> GetServices(Type serviceType) | |
{ | |
return _container.GetAllInstances<object>() | |
.Where(s => s.GetType() == serviceType); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment