Stephen Lacy
Stephen Lacy

Reputation:

Unity Static Factory Extension

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());

Upvotes: 7

Views: 3441

Answers (2)

Chris Tavares
Chris Tavares

Reputation: 30401

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.

Upvotes: 14

Damian Schenkelman
Damian Schenkelman

Reputation: 3535

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

Upvotes: 0

Related Questions