带参数的LightInject寄存器通用吗?

时间:2018-07-06 14:16:30

标签: c# dependency-injection light-inject

我有带有实现IRepository的参数构造函数的Interface IRepository和Class Repository。类和接口都是通用的。我想在注册时传递此参数。代码如下:

    public interface IRepository<T> where T : class, new()
    {
        public Task<int> InsertAsync(T entity);
    } 

   public class Repository<T> : IRepository<T> where T : class, new()
   {
      public MobileServiceClient MobileService { get; set; }

      public Repository(MobileServiceClient mobileService)
      {
        MobileService = mobileService;
      }

    public async Task<int> InsertAsync(T entity)
    {
        var table = MobileService.GetSyncTable<T>();
        await table.InsertAsync(entity);
        return 1;
    }
  }

我做了这样的通用类注册

Container.Register(typeof(IRepository<>), typeof(Repository<>));

我在注册时没有找到传递参数的方法。

0 个答案:

没有答案