Skip to content

Instantly share code, notes, and snippets.

@bsatrom
Created June 10, 2011 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsatrom/1019434 to your computer and use it in GitHub Desktop.
Save bsatrom/1019434 to your computer and use it in GitHub Desktop.
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