假设我有一个通用接口和一个通用实现。我如何注册所有用途?如何使用TinyIOC注册通用接口
具体而言,我有以下(减小为简单起见):
public interface IRepository<T> where T : TableEntity
{
T GetById(string partitionKey, string rowKey);
void Insert(T entity);
void Update(T entity);
void Update(string partitionKey, string rowKey, Action<T> updateAction);
void Delete(T entity);
IQueryable<T> Table { get; }
}
public class AzureRepository<T> : IRepository<T> where T : TableEntity
{
...
}
是否需要一个接一个地注册所有实施方式中,像这样:
container.Register<IRepository<Entity1>, AzureRepository<Entity1>>();
container.Register<IRepository<Entity2>, AzureRepository<Entity2>>();
container.Register<IRepository<Entity3>, AzureRepository<Entity3>>();
...
或者是有一个较短的方式?
这是你在找什么? https://github.com/grumpydev/TinyIoC/issues/8 – 2013-03-16 14:39:53
否 - 在此示例中,它将所有的IRepository依赖项(IR,IR 等)注册为AzureRepository 。 –
seldary
2013-03-16 19:52:42
我可以证实这种行为(在v1.2中) - 但这显然是一个错误。 – TeaDrivenDev 2013-03-30 00:55:02