dryioc - DryIoc中的autofacs“WithParameter”等价于什么?
问题描述
为了从 Autofac 迁移到 DryIoc,我遇到了一个场景,我需要将参数值传递给服务的构造函数。
// given the following class
public class SomeService
{
public SomeService(Foo foo, Bar bar) { }
}
// in autofac it looks like this
container.RegisterType<SomeService>()
.WithParameter("foo", SomeFoo.Value)
.WithParameter("bar", SomeBar.Value)
.AsSelf();
DryIoc 中的等价物是什么?
现在我正在尝试使用RegisterDelegate
,但我不确定我是否走在正确的道路上。
container.RegisterDelegate(x => new SomeService(SomeFoo.Value, SomeBar.Value));
解决方案
container.Register<SomeService>(
made: Made.Of(Parameters.Of
.Name("foo", _ => SomeFoo.Value)
.Name("bar", _ => SomeBar.Value)));
以下是可能的重载:https ://www.fuget.org/packages/DryIoc.dll/4.2.0/lib/netstandard2.0/DryIoc.dll/DryIoc/Parameters
有一个类似的Parameters
PropertiesAndFields
类来指定属性注入细节。
此外还有一个 DryIoc.Syntax.Autofac 包,您可能对https://www.fuget.org/packages/DryIoc.Syntax.Autofac.dll感兴趣
从 V1 开始,它仅涵盖 Autofac API 表面的一小部分,但我鼓励您查看它的源代码,并可能有助于 PR ot 两个 :) https://github.com/dadhi/DryIoc/tree/master/src /DryIoc.Syntax.Autofac
推荐阅读
- kubernetes-helm - 通过 helm chart 部署 Grafana UI 时不加载
- ios - 验证该任务是否由特定函数执行
- javascript - 如何在使用 vue-tree-list 插件获取树值的 ajax 响应后添加子树项
- c++ - 是否可以在 ESP32 中的 MicroPython 和 C++ 之间传递数据?
- python - PyQt5 QTableView 点击按钮更新视图
- python - 蟒蛇 - 稳定的雨
- cube.js - 当我使用 Playground/generate-schema 自动生成模式时,如何将元数据放入多维数据集的模式中?
- postgresql - 在 knex 迁移中添加和删除约束
- linux - 我现在在 snapcraft 上上传了 snap,我该如何删除它?
- java - 如何在 Applock 的锁屏上展示广告?