IoC component registration How do you list your referenced solution assemblies for IoC registration? I was really tired of typing something strange as new [] { typeof(SomeType).Assembly, … }. What do you think about the following approach?

Use case:

class Program
{
    static void Main(string[] args)
    {
        foreach (var a in Solution.Assemblies)
            Console.WriteLine(a);            
    }
}


Where Solution.Assemblies is:

public static class Solution 
{
    static IEnumerable&lt;string&gt; AssemblyNames =&gt; new[] {
        "ValueCache", "ValueCache.Tests", "LazyProxies", "ConsoleApplication1", "ClassLibrary1"
    };

    public static IEnumerable&lt;Assembly&gt; Assemblies =&gt; AssemblyNames
        .Select(an =&gt; Load(an))
        .Where(a =&gt; a != null);

    [DebuggerHidden]
    static Assembly Load(string assemblyName)
    {
        try
        {
            return Assembly.Load(new AssemblyName(assemblyName));
        }
        catch
        {
            return null;
        }
    }
}


… being generated by Solution.tt file:

&lt;#@ template debug="false" hostSpecific="true" language="C#" #&gt;
&lt;#@ output extension=".cs" #&gt;
&lt;#@ assembly name="System.Core" #&gt;
&lt;#@ assembly name="EnvDte" #&gt;
&lt;#@ import namespace="System" #&gt;
&lt;#@ import namespace="System.IO" #&gt;
&lt;#@ import namespace="System.Diagnostics" #&gt;
&lt;#@ import namespace="System.Linq" #&gt;
&lt;#@ import namespace="System.Collections" #&gt;
&lt;#@ import namespace="System.Collections.Generic" #&gt; 
&lt;#@ import namespace="System.Reflection" #&gt; 
&lt;#@ import namespace="EnvDTE" #&gt; 
&lt;#@ import namespace="Microsoft.VisualStudio.TextTemplating" #&gt;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Diagnostics;

namespace SolutionConfiguration
{
    public static class Solution 
    {
        static IEnumerable&lt;string&gt; AssemblyNames =&gt; new[] {
            &lt;#= String.Join(", ", from name in new SolutionAssemblyNames(Host)
                                  select $"\"{name}\"") #&gt;
        };

        public static IEnumerable&lt;Assembly&gt; Assemblies =&gt; AssemblyNames
            .Select(an =&gt; Load(an))
            .Where(a =&gt; a != null);

        [DebuggerHidden]
        static Assembly Load(string assemblyName)
        {
            try
            {
                return Assembly.Load(new AssemblyName(assemblyName));
            }
            catch
            {
                return null;
            }
        }
    }
}

&lt;#+

    class SolutionAssemblyNames : IEnumerable&lt;string&gt;
    {
        public SolutionAssemblyNames(ITextTemplatingEngineHost host)
        {
            Host = host;
        }

        public IEnumerator&lt;string&gt; GetEnumerator() =&gt; Assemblies.GetEnumerator();
        IEnumerator IEnumerable.GetEnumerator() =&gt; GetEnumerator();
        IEnumerable&lt;string&gt; Assemblies =&gt; Projects
            .Select(p =&gt; p?.Properties?.Item("AssemblyName")?.Value as string)
            .Distinct().Where(a =&gt; !string.IsNullOrWhiteSpace(a));

        IEnumerable&lt;Project&gt; Projects =&gt; VisualStudio.Solution.Projects.OfType&lt;Project&gt;();
        DTE VisualStudio =&gt; (Host as IServiceProvider).GetService(typeof(DTE)) as DTE;
        ITextTemplatingEngineHost Host { get; }
    }
#&gt;
This is a fascinating solution. I kept looking at it and thinking "There must be an easier way!" but every possible solution I came up with had a fatal flaw.

All I really have, then, is nitpicking:

public static IEnumerable&lt;Assembly&gt; Assemblies =&gt; AssemblyNames
        .Select(an =&gt; Load(an))


Can be simplified to:

public static IEnumerable&lt;Assembly&gt; Assemblies =&gt; AssemblyNames
    .Select(Load)


SolutionAssemblyNames is looking fairly dense. I'd add 1 line of whitespace between each property to make it a bit more readable.