Created
October 5, 2009 01:34
-
-
Save dvhthomas/201741 to your computer and use it in GitHub Desktop.
StructureMap ServiceLocation
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
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