Skip to content

Instantly share code, notes, and snippets.

@dvhthomas
Created October 5, 2009 01:34
Show Gist options
  • Save dvhthomas/201741 to your computer and use it in GitHub Desktop.
Save dvhthomas/201741 to your computer and use it in GitHub Desktop.
StructureMap ServiceLocation
using System;
using System.Collections.Generic;
using Microsoft.Practices.ServiceLocation;
using StructureMap;
namespace GisQueryDirectHost
{
public class StructureMapServiceLocator : IServiceLocator
{
#region IServiceLocator Members
public object GetService(Type serviceType)
{
return ObjectFactory.GetInstance(serviceType);
}
public object GetInstance(Type serviceType)
{
return ObjectFactory.GetInstance(serviceType);
}
public object GetInstance(Type serviceType, string key)
{
return ObjectFactory.GetNamedInstance(serviceType, key);
}
public IEnumerable<object> GetAllInstances(Type serviceType)
{
foreach (object instance in ObjectFactory.GetAllInstances(serviceType))
{
yield return instance;
}
}
public TService GetInstance<TService>()
{
return ObjectFactory.GetInstance<TService>();
}
public TService GetInstance<TService>(string key)
{
return ObjectFactory.GetNamedInstance<TService>(key);
}
public IEnumerable<TService> GetAllInstances<TService>()
{
return ObjectFactory.GetAllInstances<TService>();
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment