Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory with generic method throws ActivationException #29

Open
oslava opened this issue Sep 8, 2015 · 0 comments
Open

Factory with generic method throws ActivationException #29

oslava opened this issue Sep 8, 2015 · 0 comments

Comments

@oslava
Copy link

oslava commented Sep 8, 2015

If a factory interface has a generic method it throws ActivationException when you try to create dependency by this method.

    public interface IRecieverFactory
    {
        IReciever<TData> Get<TData>();
    }

    kernel.Bind<IRecieverFactory>().ToFactory()

StandardInstanceProvider resolves it to named binding with empty name.
I solved this problem by overriding GetName:

    public class GenericFactoryMethodInstanceProvider : StandardInstanceProvider
    {
        protected override string GetName(MethodInfo methodInfo, object[] arguments)
        {
            return null;
        }
    }
    kernel.Bind<IRecieverFactory>().ToFactory(() => new GenericFactoryMethodInstanceProvider());

This is a bug I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant