This project has moved and is read-only. For the latest updates, please go here.

work in progress

Manual Configuration

For Generics, see Generic Matching Configuration
  • Injector.ForType<MyType> is a starting point for the fluent interface. Typically, it is used to configure a concrete type before it is used as the resolver for an interface type.
    • In the example below, the MyConcrete type is configured to have a property of SomeProperty injected after an instance of MyConcrete is created.
    • Then the "As" command configures MyConcrete to be the concrete type returned for a call to Injector.Resolve<IMyInterface>().
    • Finally, another property injector sets the IFaceProperty on the interface to "Interface"

    .ForType<MyConcrete>() // for the type MyConcrete, do the following
    .AddPropertyInjector(v => v.SomeProperty) // when creating a new instance, inject a instance of the property type of SomeProperty
    .As(Injector.ForType<IMyInterface>()) // Configure MyConcrete to be returned for the interface IMyInterface
    .AddPropertyInjector(v => v.IFaceProperty, () => "Interface"); // and set the IFaceProperty 


Configure resolution for a type
  • Injector.SetResolver<IMyInterface,MyConcrete>() instructs fFastInjector to create a new instance of MyConcrete for each resolution of IMyInterface.
    • Optionally, you may pass in some Action<MyConcrete> expressions to modify the MyConcrete instance before it is returned. Injector.ToPropertyAssignmentExpression((MyConcrete v) => v.Name, () => "Horace") is a helper method that will create a property assignment expression from a property expression and a value expression that may be passed here.
  • Injector.SetResolver<IMyInterface>(() => new MyConcrete()) is an overload that accepts an expression that can be used to create a new IMyInterface
  • Each overload of the SetResolver method has a counterpart that accepts a LifetimeManager as the first parameter. The singleton lifetime manager looks like this Injector.LifetimeManager<I8>.Singleton. You can write your own lifetime manager or find others in the fFastInjector power tools
SetResolver returns a fluent object, so you can tack on property injectors with AddPropertyInjector. SetResolver<IMyInterface,MyConcrete>().AddPropertyInjector(v=> v.SomeProperty) will inject an instance of the property type of SomeProperty
  • SetGenericResolver(openGeneric, concreteOpenGeneric, artificialConstraints) see Generic Matching Configuration
  • SetSingletonResolverAsInstance<T> sets a specific instance to be returned for any call to resolve this type
  • SetSingletonResolver<T,TConcreteType> sets a specific type of TConcreteType as the resolver for T and sets the LifetimeManager to Singleton

Last edited Jan 10, 2015 at 2:21 PM by Grax, version 3


No comments yet.