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

When querying of the binding metadata expose the Implementation Type #35

Closed
drusellers opened this Issue Apr 24, 2011 · 5 comments

Comments

Projects
None yet
3 participants
@drusellers

drusellers commented Apr 24, 2011

When trying to query the metadata of the bindings in the container I am finding it very difficult to get the type that is bound to the interface.

So given

kernel.Bind<IConsumer>().To<FakeConsumer>();

How do I get the concrete type of the binding.
At the moment this is what I believe it takes.

var k = new StandardKernel();
k.Bind<IConsumer>().To<FakeConsumer>();

foreach (var binding in k.GetBindings(typeof(IConsumer)))
{
    var cb = binding.ProviderCallback;
    var req = new Request(null, typeof(IConsumer), null, () => null);
    var x = cb(new Context(k, req, null, null, null, null));
    var concrete = x.Type; //<- this is what I want
}
@remogloor

This comment has been minimized.

Show comment
Hide comment
@remogloor

remogloor Apr 24, 2011

Member
  1. It is technically not possible to get to implementation type because of several overloads e.g. ToMethod and ToProvider return some unknown type whose only requirement is that it implements the type of the binding. Furthermore, they can even return several types e.g. ToMethod(ctx => IsSunday ? new SundayImplementation() : new WeekdayImplementation()). So whats the implementation type in this scenario?
  2. I still do not see any scenario that requires to know the implementation type. Ninject is a big factory which is responsible to put classes together. The only time the implementation must be known is internally in Ninject at the time of resolve.

Unless you can show any valid scenario that requires lookup of the implementation type no action will be taken.

Member

remogloor commented Apr 24, 2011

  1. It is technically not possible to get to implementation type because of several overloads e.g. ToMethod and ToProvider return some unknown type whose only requirement is that it implements the type of the binding. Furthermore, they can even return several types e.g. ToMethod(ctx => IsSunday ? new SundayImplementation() : new WeekdayImplementation()). So whats the implementation type in this scenario?
  2. I still do not see any scenario that requires to know the implementation type. Ninject is a big factory which is responsible to put classes together. The only time the implementation must be known is internally in Ninject at the time of resolve.

Unless you can show any valid scenario that requires lookup of the implementation type no action will be taken.

@remogloor remogloor closed this Apr 24, 2011

@drusellers

This comment has been minimized.

Show comment
Hide comment
@drusellers

drusellers Apr 24, 2011

The only scenario I have is for bringing Ninject and MassTransit integration tighter than it currently is. Thank you for taking the time to answer. :)

drusellers commented Apr 24, 2011

The only scenario I have is for bringing Ninject and MassTransit integration tighter than it currently is. Thank you for taking the time to answer. :)

@danielmarbach

This comment has been minimized.

Show comment
Hide comment
@danielmarbach

danielmarbach Dec 22, 2011

Member

If I understand correctly with the new API changes this should be possible. And also with the convention extension we have the ability to auto scan for consumers

Member

danielmarbach commented Dec 22, 2011

If I understand correctly with the new API changes this should be possible. And also with the convention extension we have the ability to auto scan for consumers

@drusellers

This comment has been minimized.

Show comment
Hide comment
@drusellers

drusellers Dec 22, 2011

i would be interested to review this when the new version drops

drusellers commented Dec 22, 2011

i would be interested to review this when the new version drops

@remogloor

This comment has been minimized.

Show comment
Hide comment
@remogloor

remogloor Dec 22, 2011

Member

No the situation is still the same. It's not possible to tell what's the implementation for several binding types e.g. ToMethod and ToProvider

Member

remogloor commented Dec 22, 2011

No the situation is still the same. It's not possible to tell what's the implementation for several binding types e.g. ToMethod and ToProvider

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