Skip to content

Factory with generic method throws ActivationException #29

Description

@oslava

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions