Unity 静态工厂扩展

发布于 2024-09-25 21:51:33 字数 162 浏览 4 评论 0原文

我似乎无法在任何地方找到 Microsoft.Practices.Unity.StaticFactory.dll。

还有其他注册静态工厂的方法吗?

寻找类似的

容器.RegisterFactory(()=> FooFactory.CreateFoo());

I can't seem to find Microsoft.Practices.Unity.StaticFactory.dll anywhere.

Is there another way of registering a static factory?

Looking for something like this

container.RegisterFactory(()=> FooFactory.CreateFoo());

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

就此别过 2024-10-02 21:51:33

StaticFactory.dll 作为 Unity 2.0 的一部分被纳入主程序集中。它通常非常有用,因此我们不想强迫人们为了获取它而携带单独的 DLL。

因此,您仍然可以使用现有的 API,只是不需要添加程序集引用。但是,我们已弃用旧的 API。可以添加扩展,但不执行任何操作,它已包含在容器中。现在,您可以通过以下方式在容器中注册工厂:

  container.RegisterType<IFoo, Foo>(new InjectionFactory(c => new Foo());

其中 c 是解析实例的容器。还有一个选项可以传递正在解析的类型和名称。

我们弃用了旧的 API,因为它使用起来非常尴尬,而且无论如何它都不再是一个扩展了。

StaticFactory.dll was rolled into the main assembly as part of Unity 2.0. It was generally useful enough that we didn't want to force people to carry around a separate DLL just to get it.

As such, you can still use the existing API, you just don't need to add the assembly reference. However, we've deprecated the old API. The extension can be added, but does nothing, it's already included in the container. And you can now register factories in the container by saying:

  container.RegisterType<IFoo, Foo>(new InjectionFactory(c => new Foo());

where c is the container that's resolving the instance. There's also an option to pass in the type and name being resolved as well.

We deprecated the old API because it was very awkward to use and it's not an extension anymore anyway.

熊抱啵儿 2024-10-02 21:51:33

RegisterFactory 方法是 StaticFactoryExtension 类,它已被弃用,您可以看到

如果您正在寻找工厂扩展,此线程应该会有所帮助。

我希望这有帮助。

谢谢,
达米安

The RegisterFactory method is part of the StaticFactoryExtension class, which is deprecated as you can see here.

If you are looking for factory extensions, this thread should be helpful.

I hope this helps.

Thanks,
Damian

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文