views:

45

answers:

2

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

A: 

Hi,

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

Damian Schenkelman
Why is it deprecated?
Stephen lacy
As it says in the link I provided: [ObsoleteAttribute("Use RegisterType<TInterface, TImpl>(new InjectionFactory(...)) instead of the extension's methods.")]
Damian Schenkelman
+2  A: 

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.

Chris Tavares