Reduce duplication while accessing Visual Studio services If you write a VS extension, you can get access to VS services with the IServiceProvider interface:

var vsUIShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsVsUIShell));
vsUIShell.SetWaitCursor(); // for example


To reduce duplication every time I need this, I created a class like this:

static class VisualStudioServices
{
    public static IVsUIShell UIShell { get { return vsUIShell.Service; } } 
    static readonly LazyService&lt;SVsUIShell, IVsUIShell&gt; vsUIShell = new LazyService&lt;SVsUIShell, IVsUIShell&gt;();

    class LazyService&lt;TService, T&gt;
    {
        static T GetService()
        {
            return (T)ServiceProvider.GlobalProvider.GetService(typeof(TService));
        }

        readonly Lazy&lt;T&gt; serviceLazy = new Lazy&lt;T&gt;(GetService);

        public T Service { get { return this.serviceLazy.Value; } }
    }
}


To add a new service to the list, I have to mention its name 8 time (assuming the Service type and the interface type are the same, which is not always true).

I'm looking for a way to reduce this duplication further. Any suggestions?
Your current design will potentially make unit testing code which uses it hard. Consider making the VisualStudioServices class non-static and create an interface for it. You could then inject the ServiceProvider as a dependency rather having an implicit dependency on the static GlobalProvider. Something like this:

interface IVisualStudioServices
{
    IVsUIShell UIShell { get; }
}

class VisualStudioServices : IVisualStudioServices
{
    public IVsUIShell UIShell { get { return _VsUiShell.Service; } }

    private readonly LazyService&lt;SVsUIShell, IVsUIShell&gt; _VsUiShell; 

    public VisualStudioServices(ServiceProvider serviceProvider)
    {
        _VsUiShell = new LazyService&lt;SVsUIShell, IVsUIShell&gt;(serviceProvider);
    }

    class LazyService&lt;TService, T&gt;
    {
        ServiceProvider _ServiceProvider;
        LazyService(ServiceProvider serviceProvider)
        {
            _ServiceProvider = serviceProvider;
        }

        readonly Lazy&lt;T&gt; serviceLazy = new Lazy&lt;T&gt;(() =&gt; (T)_ServiceProvider.GetService(typeof(TService)));

        public T Service { get { return serviceLazy.Value; } }
    }
}


Any code requiring access to it should have a dependency on IVisualStudioServices which can be easily mocked out.