Skip to content
This project provides automatic Abstract Factory functionality similar to Castle.Windsor Typed Factories, for the Unity IoC container.
C#
Latest commit 9c32745 Jul 27, 2015 @PombeirP Merge pull request #6 from metatem/master
New extension methods

README.md

Unity.TypedFactories

This project provides automatic Automatic Factory functionality similar to Castle.Windsor Typed Factories, for the Unity IoC container.

Usage

The library takes as an input an interface to be used as the factory interface.

It generates a proxy object upon resolution of this factory interface, with an implementation for each method of the interface that returns a reference object.

The factory interface is configured for a given concrete type, and the factory method's arguments are matched by name to the created object's constructor arguments.

unityContainer
    .RegisterTypedFactory<IFooFactory>()
    .ForConcreteType<Foo>();    // It is assumed that Foo implements the interface returned by the method declared in the IFooFactory. A NotImplementedException will be thrown upon invocation of the factory method otherwise.

public interface IFooFactory
{
    #region Public Methods and Operators

    IFoo Create(uint id);

    #endregion
}

In case an argument from the constructor is not provided by either the factory method or the IoC container, then a ConstructorArgumentsMismatchException exception will be thrown, detailing the missing arguments.

Something went wrong with that request. Please try again.