Splat.DI.SourceGenerator icon indicating copy to clipboard operation
Splat.DI.SourceGenerator copied to clipboard

Support IEnumerable dependencies

Open MGRussell opened this issue 4 years ago • 0 comments

IEnumerables in constructor injection (and I assume, but have not tested, property injection) are currently not being initialized and left as null. They should be resolved by Locator.Current.GetServices<Dependency>().

Here is a helper method workaround in the meantime.

public static void ResolveIEnumerable<T>(ref IEnumerable<T> target)
{
    // https://github.com/reactivemarbles/Splat.DI.SourceGenerator/issues/72
    if (target != null)
    {
        throw new InvalidOperationException("This issue has been resolved. Remove this method.");
    }

    target = Locator.Current.GetServices<T>();
}

MGRussell avatar Nov 19 '21 06:11 MGRussell