1 回答
TA贡献1725条经验 获得超7个赞
container.Register<Ixxx, Data>();
_container.Register<IData<Ixxx>, XxxData>();
_container.RegisterDecorator<IData<Ixxx>, Data1Decorator<Ixxx>>();
_container.RegisterDecorator<IData<Ixxx>, Data2Decorator<Ixxx>>():
public interface IData<out TData>
{
TData Data { get; }
Task Load();
}
public abstract class DataDecorator<TData> : IData<TData>
{
public readonly IData<TData> _data;
public TData Data => _data.Data;
protected DataDecorator(IData<TData> data) => _data = data;
public virtual Task Load() => _data.Load();
}
public interface Ixxx :
Ixxx1,
Ixxx2
{
}
public class XxxData : IData<Ixxx>
{
public Ixxx Data { get; }
public XxxData(Ixxx data) => Data = data;
public Task Load() => Task.Run(() => { });
}
public interface Ixxx1
{
public IEnumerable<...> x1 { get; set; }
}
public class Data1Decorator<TData> : DataDecorator<TData>
where TData : Ixxx1
{
public Data1Decorator(IData data) : base(data)
{
}
public override Task Load()
{
return Task.WhenAll(new List<Task>() { ..., base.Load() })
.ContinueWith((b) =>
{
Data.x1 = ...
});
}
}
- 1 回答
- 0 关注
- 119 浏览
添加回答
举报