jcansdale / TestDriven.Net-Issues

Issue tracking for TestDriven.Net
https://github.com/jcansdale/TestDriven.Net-Issues/issues
24 stars 2 forks source link

Allow Visual Studio services to be passed into constructor for instance methods #130

Open jcansdale opened 6 years ago

jcansdale commented 6 years ago

MEF importing constructors are now supported, but a little ceremony is required to use with Visual Studio services.

For example, it's now possible to do the following:

[Export]
class DteTests
{
    DTE dte;

    [ImportingConstructor]
    Foo(SVsServiceProvider sp)
    {
        this.dte = (DTE)sp.GetServiceProvider(typeof(DTE));
    }

    void Test()
    {
        Console.WriteLine(dte.FileName);
    }
}

It would be more convenient if we could instead do this:

class DteTests
{
    DTE dte;

    Foo(DTE dte)
    {
        this.dte = dte;
    }

    void Test()
    {
        Console.WriteLine(dte.FileName);
    }
}

There are other ways, but this could be a handy shortcut if a little setup is required.