Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top