fmys

实现IContributeComponentConstruction接口 

意如其名,组件创建后它将完成组件最后状态的构建

不建议在construction contributor意外的地方修改ComponentModel,construction contributor构建好组建后认为他是只读的,修改会带来同步和难以跟踪的问题。

 

自定义Contributor

public class RequireLoggerProperties : IContributeComponentModelConstruction
{
    public void ProcessModel(IKernel kernel, ComponentModel model)
    {
        model.Properties
        .Where(p => p.Dependency.TargetType == typeof(ILogger))
        .All(p => p.Dependency.IsOptional = false);
    }
}

container.Kernel.ComponentModelBuilder.AddContributor(new RequireLoggerProperties());  //将自定义的Contibutor添加到容器。

上面的自定义Constructor循环组件的依赖查找类型为ILogger的依赖,设置为必须的。

 

分类:

技术点:

相关文章:

  • 2021-07-15
  • 2021-12-19
  • 2021-09-10
  • 2021-09-08
  • 2021-11-13
  • 2021-07-26
  • 2021-06-30
  • 2021-08-16
猜你喜欢
  • 2021-09-24
  • 2021-09-12
  • 2021-07-14
  • 2021-04-07
  • 2022-01-12
  • 2021-12-14
  • 2022-03-08
相关资源
相似解决方案