Konstruktor Generator Functions

Beginning with revision 9, Konstruktor supports explicit generator functions:

To register a function, the method Builder.generator<TargetType>(Func<IScope, TargetType>) can be used.

Whenever “TargetType” needs to be constructed, the generator function is called, for example:

    interface IGeneratorExample
    {}
    sealed class GeneratorExample : IGeneratorExample
    {
    }
    [Test]
    public static void explicitGenerator()
    {
      var b = new Builder();
      b.generator<IGeneratorExample>(scope => new GeneratorExample());
      using (var s = b.beginScope())
      {
        var generated = s.resolve<IGeneratorExample>();
        Assert.AreEqual(typeof (GeneratorExample), generated.GetType());
      }
    }

Now, field and property injection is possible by modifying the created instance:

    sealed class PropertyInjection
    {
      public GeneratorExample Generator { get; set; }
    }
    [Test]
    public static void explicitGeneratorPropertyInjection()
    {
      var b = new Builder();

b.generator(scope => new PropertyInjection

{Generator = scope.resolve<GeneratorExample>()});

      using (var s = b.beginScope())
      {
        var generated = s.resolve<PropertyInjection>();
        Assert.AreEqual(typeof(PropertyInjection), generated.GetType());
        Assert.AreNotEqual(null, generated.Generator);
      }
    }
You can download the new source and binary files here.