문제

I have my general bindings, and one of which is this:

Bind<IHasher>().To<SHA256Hasher>();

This works great, as there are a few classes throughout which use this hasher. However there are one or two controllers which require another type of hasher for using the hash with 3rd parties, such as gravatar which expect md5 hashes. So then I do the below:

Bind<ISomeController>().To<SomeController>().Named("SomeController").WithConstructorArgument("emailHasher", new Md5Hasher());

Then my controller looks like:

    public class SomeController : Controller
    {
        private IHasher emailHasher;

        public CampaignController(IHasher emailHasher)
        {
            this.emailHasher = emailHasher;
        }
    }

When debugging I would expect the IHasher to be Md5Hasher, however it is an Sha256Hasher. So is this expected behaviour and any way to make it use the overridden type?

도움이 되었습니까?

해결책

I suppose this is an MVC controller. The MVC Framework will resolve a SomeController not an ISomeController. Hence your binding does not apply but Ninject will use the implicit binding SomeController ToSelf instead.

Create a binding for SomeController ToSelf instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top