【Autofac笔记】服务定位器
public interface IServiceLocator
{
object GetService(Type type);
}
public class ServiceLocator : IServiceLocator
{
private readonly ILifetimeScope _lifetimeScope;
public ServiceLocator( ILifetimeScope lifetimeScope)
{
_lifetimeScope = lifetimeScope;
}
public object GetService(Type type)
{
return _lifetimeScope.Resolve(type);
}
}