tags:

views:

29

answers:

1

I have just downloaded the latest version of Ninject and replaced our existing Ninject.Core and Ninject.Condidtions assemblies with the single Ninject.dll (CF builds if that makes a difference). All has gone smoothly until I get to:

kernel.Components.Connect<IMemberSelector>(new MyMemberSelector());

Which is implemented:

public class MyMemberSelector : ConventionMemberSelector
{
    protected override void DeclareHeuristics()
    {
        InjectProperties(When.Property.Name.StartsWith("View"));
    }
}

I can't find any reference to what this has been replaced with and my bindings don't just work - the View properties aren't injected.

Can anyone help?

Thanks

+2  A: 

You can implement your own IInjectionHeuristic and add it as a Kernel component.

var selector = kernel.Components.Get<ISelector>();
var heuristic = new PropertyMemberSelector(member => member.Name.StartsWith("View"));
selector.InjectionHeuristics.Add(heuristic);


public class PropertyMemberSelector
    : NinjectComponent, IInjectionHeuristic
{
    private readonly Func<MemberInfo, bool> _predicate;

    public PropertyMemberSelector(Func<MemberInfo, bool> predicate)
    {
        _predicate = predicate;
    }

    public bool ShouldInject(MemberInfo member)
    {
        return member.MemberType == MemberTypes.Property && _predicate( member );
    }
}

Regards,

Ian

Ian Davis
VNice. Silly question, where's the best single place to find info re all this new good stuff? (If the answer is that the best approach to this is to look at the source, please say it -- it definitely is for xUnit.net for example -- but for 1.0 the dojo was pretty complete)
Ruben Bartelink
We are working on the new dojo with the Ninject github wiki and I am writing blog posts on features and extensions in 2.0 - there is a lot to cover.
Ian Davis