seesharper / LightInject

An ultra lightweight IoC container
http://www.lightinject.net
MIT License
615 stars 122 forks source link

Alternative to MEF plugins #531

Open WonkySoft opened 4 years ago

WonkySoft commented 4 years ago

I have reflection code that lets me scan/load any assembly that has methods that meet a given signature and create proxies to those methods. It doesn't rely on any defined interface or attributes on the methods. I'm pretty sure I can achieve the same thing with MEF 1.0 and attributes, but ConventionBuilder in MEF 2.0 isn't documented well enough to determine if I can achieve the same thing without attributes.

So my question is, can this be (easily) achieved with LightInject? If so, can someone provide a simple example.

seesharper commented 4 years ago

Hi @WonkySoft Could you come with a simple example/repro of what you are trying to do? 😊

WonkySoft commented 4 years ago

Say each one of these is defined in a separate assembly:

public static class StaticThing
{
    public static Task<bool> MyStaticMethod() =>
        Task.FromResult(true);
}

public class InstanceThing
{
    public Task<bool> MyInstanceMethod() =>
        Task.FromResult(true);
}

public class InstanceWithStaticThing
{
    public static Task<bool> MyStaticMethod() =>
        Task.FromResult(true);
}

I want to be able to discover and proxy said methods from their assemblies in a given path based on method signature match, which in this case is something like Func<Task<bool>>.

WonkySoft commented 4 years ago

Was the information I added sufficient?