Skip to content

Factory with generic method throws ActivationException #29

@oslava

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions