public void RegisterBaseType()
        {
            ///创建注册器
            IDependencyRegister register = container.CreateRegister();
            ///注册实现特定接口或基类的类型
            var assembly = register.RegisterAssembly <IDependency>(Assembly.GetExecutingAssembly());

            using (IDependencyResolver resolver = container.CreateResolver())
            {
                var results = resolver.ResolveAll <IDependency>();
                foreach (var value in results)
                {
                    Assert.IsNotNull(value);
                    Assert.IsInstanceOfType(value, typeof(IDependency));
                }
            }
        }
        public void RegisterNamed()
        {
            ///创建注册器
            IDependencyRegister register = container.CreateRegister();

            ///注册程序集中符合约定名称的类型
            register.RegisterAssembly("Repository", Assembly.GetExecutingAssembly());
            ///创建解析器
            using (IDependencyResolver resolver = container.CreateResolver())
            {
                var results = resolver.ResolveAll <IRepository <UserEntity> >();
                foreach (var value in results)
                {
                    Assert.IsNotNull(value);
                    Assert.IsInstanceOfType(value, typeof(IRepository <UserEntity>));
                }
            }
        }
        public void RegisterGeneric()
        {
            ///创建注册器
            IDependencyRegister register = container.CreateRegister();

            ///注册实现特定泛型类型定义IRepository<>的类型
            register.RegisterAssembly(typeof(IRepository <>), Assembly.GetExecutingAssembly());
            ///创建解析器
            using (IDependencyResolver resolver = container.CreateResolver())
            {
                ///解析实现特定泛型类型定义IRepository<>的类型
                var results = resolver.ResolveAll(typeof(IRepository <>));
                foreach (var value in results)
                {
                    Assert.IsNotNull(value);
                    Assert.IsInstanceOfType(value, typeof(IRepository <UserEntity>));
                }
            }
        }
 /// <summary>
 /// 注册 程序集
 /// </summary>
 public static IEnumerableRegistration RegisterAssembly <TBaseService>(this IDependencyRegister dependencyRegister, Assembly assembly)
     where TBaseService : class
 {
     return(dependencyRegister.RegisterAssembly(assembly, typeof(TBaseService)));
 }
Exemple #5
0
 /// <summary>
 ///    注册程序集中使实现特定接口或基类的类型作为依赖服务
 /// </summary>
 public static IEnumerableRegistration RegisterAssembly <TBaseService>(
     this IDependencyRegister dependencyRegister, params Assembly[] assemblys)
     where TBaseService : class => dependencyRegister.RegisterAssembly(typeof(TBaseService), assemblys);