I updated an old Castle.Windsor dll to the new NuGet one...
Actually I heve the folowing error:
'Castle.Windsor.IWindsorContainer' does not contain a definition for 'GetService' and no extension method 'GetService' accepting a first argument of type 'Castle.Windsor.IWindsorContainer' could be found (are you missing a using directive or an assembly reference?)
this is my code:
/// <summary>
/// IoC Abstraction
/// </summary>
public class ServiceLocator : IServiceLocator
{
private IWindsorContainer _container;
private ServiceLocator(IWindsorContainer container)
{
_container = container;
}
private static IServiceLocator _current;
public static IServiceLocator Current
{
get { return _current; }
set { _current = value; }
}
public static void Register(IWindsorContainer container)
{
_current = new ServiceLocator(container);
}
public T GetInstance<T>()
{
return (T)_container.GetService(typeof(T));
}
public object GetInstance(Type t)
{
return _container.GetService(t);
}
public T GetService<T>()
{
return (T)_container.GetService(typeof(T));
}
public object GetService(Type t)
{
return _container.GetService(t);
}
}
You should use Resolve method overloads:
public T GetInstance<T>()
{
return _container.Resolve<T>();
}
public object GetInstance(Type t)
{
return _container.Resolve(t);
}