【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);
        }
    }
posted @ 2021-01-16 15:10  .Neterr  阅读(37)  评论(0编辑  收藏  举报