我有接口 IRepository 和 Class Repository 以及实现 IRepository 的参数构造函数。类和接口都是通用的。我想在注册时传递这个参数。代码如下:
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<>));
我在注册时找不到传递参数的方法。