diff --git a/src/Prism.Container.Extensions/ContainerLocator.cs b/src/Prism.Container.Extensions/ContainerLocator.cs index dc81a55..0f3f855 100644 --- a/src/Prism.Container.Extensions/ContainerLocator.cs +++ b/src/Prism.Container.Extensions/ContainerLocator.cs @@ -29,6 +29,19 @@ public static IContainerExtension Locate() return _locatedExtension.Container; } + internal static void LocatePreservedReference(Type type) + { + if (_locatedExtension is null) + { + if (!LocatedAssembly(new[] { type.Assembly }, out _locatedExtension)) + { + throw new DllNotFoundException("No assembly containing a reference to an IContainerExtension implementation could be found. You must have a reference to one of the DI Container Extensions in your final project"); + } + + Console.WriteLine($"Located Container: {_locatedExtension.Container.GetType().FullName}"); + } + } + private static bool LocatedAssembly(IEnumerable assemblies, out ContainerExtensionAttribute attribute) { attribute = null; diff --git a/src/Prism.Container.Extensions/PreserveAttribute.cs b/src/Prism.Container.Extensions/PreserveAttribute.cs index ef26b56..07264f7 100644 --- a/src/Prism.Container.Extensions/PreserveAttribute.cs +++ b/src/Prism.Container.Extensions/PreserveAttribute.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using Prism.Ioc; namespace Prism.Container.Extensions { @@ -36,6 +37,10 @@ public PreserveAttribute() public PreserveAttribute(Type referenceType) : this(true, false) { + if(typeof(IContainerExtension).IsAssignableFrom(referenceType)) + { + ContainerLocator.LocatePreservedReference(referenceType); + } } } }