autofac泛型接口可以进行注入吗?而且还有参数。如果可以请贴出来!谢谢!

解决方案 »

  1.   

    感觉应该不行,你没有确定IRepository类型。
      

  2.   

    我写了个测试代码,这样是可以的class Program
        {        static void Main(string[] args)
            {            UserService u = new UserService();
                u.Show();            Console.ReadLine();
            }            }    public class BaseEntity { }    public class User :BaseEntity
        {       
        }    public interface IRepository<T>
        {
            void Show();
        }    public class UserDAL : IRepository<User>
        {        public void Show()
            {
                Console.WriteLine("hello") ;
            }
        }    public interface IService<T> 
        {
            
        }    public class BaseService<K,T>:IService<T> where T:BaseEntity
                                                  where K:IRepository<T>,new()
        {
            //这里自己配置autofac
            K _IRepository=new K();        public void Show()
            {
                _IRepository.Show();
            }
        }    public class UserService : BaseService<UserDAL, User>
        {
            
        }
      

  3.   

    啊,我记得core框架是可以的,但是autofac可能不行,我用的webapi
      

  4.   

    已经解决了,通过ddd模式可以解决这种问题。不需要关心这种问题。