Skip to content

Commit

Permalink
move container extensions to shared projects
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Apr 12, 2020
1 parent 2cfa5cc commit d9f7ebe
Show file tree
Hide file tree
Showing 34 changed files with 762 additions and 348 deletions.
17 changes: 17 additions & 0 deletions PrismLibrary.sln
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,24 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.DI.Forms.Tests", "tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.shproj", "{FAC4FA5A-D6C1-4787-9B1F-A3EC6E2FB26E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Containers", "Containers", "{75B1C655-8365-4130-8B79-C748BF0403F2}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.Unity.Shared", "src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.shproj", "{D66336A6-07E5-401A-A710-DAEDD6975D59}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.DryIoc.Shared", "src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.shproj", "{6E7EC81D-DA39-4C4F-A898-0148558C34F4}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.projitems*{089c5e84-52c3-409e-924c-bd8f4833594b}*SharedItemsImports = 5
src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{0c8aab85-387c-41d2-abce-bafaf74b62b2}*SharedItemsImports = 5
tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.projitems*{367be810-5b34-4894-be47-1c8dcc67de81}*SharedItemsImports = 5
src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{6e7ec81d-da39-4c4f-a898-0148558c34f4}*SharedItemsImports = 13
src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{aad8a958-546b-4b7d-bbd1-d79e825530eb}*SharedItemsImports = 5
tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.projitems*{ba05687e-2317-4a65-805b-c596f52f7203}*SharedItemsImports = 5
src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{c2f58215-92f0-4501-a9f4-862c78b2b4ce}*SharedItemsImports = 5
tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.projitems*{c2ff8459-f2d1-4b87-a31a-82a1835f89cf}*SharedItemsImports = 5
src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{d66336a6-07e5-401a-a710-daedd6975d59}*SharedItemsImports = 13
src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{e9a2458b-999d-4d36-822f-663d3830575a}*SharedItemsImports = 5
tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.projitems*{fac4fa5a-d6c1-4787-9b1f-a3ec6e2fb26e}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -278,6 +292,9 @@ Global
{367BE810-5B34-4894-BE47-1C8DCC67DE81} = {F1F91777-01EA-43A3-A3ED-D473B382F46C}
{2E8F565D-9D13-424E-BD86-C5A362F9AAE7} = {F1F91777-01EA-43A3-A3ED-D473B382F46C}
{FAC4FA5A-D6C1-4787-9B1F-A3EC6E2FB26E} = {F8A0FDE6-8E75-47D1-9E33-02AB8E8AB473}
{75B1C655-8365-4130-8B79-C748BF0403F2} = {F3664D7A-6FF5-4D1F-9F5F-26EE87F032D3}
{D66336A6-07E5-401A-A710-DAEDD6975D59} = {75B1C655-8365-4130-8B79-C748BF0403F2}
{6E7EC81D-DA39-4C4F-A898-0148558C34F4} = {75B1C655-8365-4130-8B79-C748BF0403F2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C7433AE2-B1A0-4C1A-887E-5CAA7AAF67A6}
Expand Down
13 changes: 13 additions & 0 deletions PrismLibrary_Forms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Unity.Forms.Tests", "
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.DI.Forms.Tests", "tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.shproj", "{FAC4FA5A-D6C1-4787-9B1F-A3EC6E2FB26E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Container", "Container", "{09DC3C91-141C-468E-9CE6-71091A95BED8}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.Unity.Shared", "src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.shproj", "{D66336A6-07E5-401A-A710-DAEDD6975D59}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.DryIoc.Shared", "src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.shproj", "{6E7EC81D-DA39-4C4F-A898-0148558C34F4}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.projitems*{2fd30caf-6930-41f3-8104-3d018c8bdd9e}*SharedItemsImports = 5
tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.projitems*{3cba8db4-c2f3-41cb-b5f5-4c282939d429}*SharedItemsImports = 5
src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{5923689a-fbe9-4b22-8938-de554bed3144}*SharedItemsImports = 5
src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{6e7ec81d-da39-4c4f-a898-0148558c34f4}*SharedItemsImports = 13
src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{d4fe645d-0924-4a20-a081-27a0aff3adfa}*SharedItemsImports = 5
src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{d66336a6-07e5-401a-a710-daedd6975d59}*SharedItemsImports = 13
tests\Forms\Prism.DI.Forms.Tests\Prism.DI.Forms.Tests.projitems*{fac4fa5a-d6c1-4787-9b1f-a3ec6e2fb26e}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -156,6 +166,9 @@ Global
{3CBA8DB4-C2F3-41CB-B5F5-4C282939D429} = {CF8CB255-8A76-48A7-B09A-88B14648D3A8}
{2FD30CAF-6930-41F3-8104-3D018C8BDD9E} = {CF8CB255-8A76-48A7-B09A-88B14648D3A8}
{FAC4FA5A-D6C1-4787-9B1F-A3EC6E2FB26E} = {CF8CB255-8A76-48A7-B09A-88B14648D3A8}
{09DC3C91-141C-468E-9CE6-71091A95BED8} = {07A089D7-5FAF-492A-BE7F-B854E255E32C}
{D66336A6-07E5-401A-A710-DAEDD6975D59} = {09DC3C91-141C-468E-9CE6-71091A95BED8}
{6E7EC81D-DA39-4C4F-A898-0148558C34F4} = {09DC3C91-141C-468E-9CE6-71091A95BED8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E03CA9C3-F24B-442E-B378-C325728E9E29}
Expand Down
14 changes: 14 additions & 0 deletions PrismLibrary_Wpf.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.IocContainer.Wpf.Test
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.Container.Wpf.Shared", "tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.shproj", "{BD42A7D6-A84D-4D27-9C28-7F6A2EC477F1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Containers", "Containers", "{3CD6B945-4E76-4DC7-A68A-972C36ADA718}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.DryIoc.Shared", "src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.shproj", "{6E7EC81D-DA39-4C4F-A898-0148558C34F4}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Prism.Unity.Shared", "src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.shproj", "{D66336A6-07E5-401A-A710-DAEDD6975D59}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{2f184285-b860-4c68-aaf7-73af6b2f98d8}*SharedItemsImports = 5
src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{6e7ec81d-da39-4c4f-a898-0148558c34f4}*SharedItemsImports = 13
src\Containers\Prism.DryIoc.Shared\Prism.DryIoc.Shared.projitems*{a2976e8c-589a-47c7-b81d-d59cbced2e0b}*SharedItemsImports = 5
tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.projitems*{a60cf7b0-56ad-4568-9720-e30ee5855149}*SharedItemsImports = 5
tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.projitems*{bd42a7d6-a84d-4d27-9c28-7f6a2ec477f1}*SharedItemsImports = 13
src\Containers\Prism.Unity.Shared\Prism.Unity.Shared.projitems*{d66336a6-07e5-401a-a710-daedd6975d59}*SharedItemsImports = 13
tests\Wpf\Prism.Container.Wpf.Shared\Prism.Container.Wpf.Shared.projitems*{fd11fa19-6a06-471d-8471-94c1153104cd}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -170,6 +181,9 @@ Global
{FD11FA19-6A06-471D-8471-94C1153104CD} = {414633C4-2FB9-4A81-8071-832C33C027BC}
{4039BC28-15D4-4EE1-82D8-80BD4CC61C50} = {414633C4-2FB9-4A81-8071-832C33C027BC}
{BD42A7D6-A84D-4D27-9C28-7F6A2EC477F1} = {414633C4-2FB9-4A81-8071-832C33C027BC}
{3CD6B945-4E76-4DC7-A68A-972C36ADA718} = {0DF20AD9-0A3F-4B61-BC8A-2D6DED59A7D2}
{6E7EC81D-DA39-4C4F-A898-0148558C34F4} = {3CD6B945-4E76-4DC7-A68A-972C36ADA718}
{D66336A6-07E5-401A-A710-DAEDD6975D59} = {3CD6B945-4E76-4DC7-A68A-972C36ADA718}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {544BBD3D-C3AA-405A-9832-122679F8AD05}
Expand Down
177 changes: 177 additions & 0 deletions src/Containers/Prism.DryIoc.Shared/DryIocContainerExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using System;
using System.Linq;
using DryIoc;
using Prism.Ioc;

namespace Prism.DryIoc
{
/// <summary>
/// The <see cref="IContainerExtension" /> Implementation to use with DryIoc
/// </summary>
public class DryIocContainerExtension : IContainerExtension<IContainer>
{
/// <summary>
/// The instance of the wrapped container
/// </summary>
public IContainer Instance { get; }

/// <summary>
/// Constructs a new <see cref="DryIocContainerExtension" />
/// </summary>
/// <param name="container">The <see cref="IContainer" /> instance to use.</param>
public DryIocContainerExtension(IContainer container)
{
Instance = container;
Instance.RegisterInstanceMany(new[]
{
typeof(IContainerExtension),
typeof(IContainerProvider)
}, this);
}

/// <summary>
/// Used to perform any final steps for configuring the extension that may be required by the container.
/// </summary>
public void FinalizeExtension() { }

/// <summary>
/// Registers an instance of a given <see cref="Type"/>
/// </summary>
/// <param name="type">The service <see cref="Type"/> that is being registered</param>
/// <param name="instance">The instance of the service or <see cref="Type" /></param>
/// <returns>The <see cref="IContainerRegistry" /> instance</returns>
public IContainerRegistry RegisterInstance(Type type, object instance)
{
Instance.RegisterInstance(type, instance);
return this;
}

/// <summary>
/// Registers an instance of a given <see cref="Type"/> with the specified name or key
/// </summary>
/// <param name="type">The service <see cref="Type"/> that is being registered</param>
/// <param name="instance">The instance of the service or <see cref="Type" /></param>
/// <param name="name">The name or key to register the service</param>
/// <returns>The <see cref="IContainerRegistry" /> instance</returns>
public IContainerRegistry RegisterInstance(Type type, object instance, string name)
{
Instance.RegisterInstance(type, instance, serviceKey: name);
return this;
}

/// <summary>
/// Registers a Singleton with the given service and mapping to the specified implementation <see cref="Type" />.
/// </summary>
/// <param name="from">The service <see cref="Type" /></param>
/// <param name="to">The implementation <see cref="Type" /></param>
/// <returns>The <see cref="IContainerRegistry" /> instance</returns>
public IContainerRegistry RegisterSingleton(Type from, Type to)
{
Instance.Register(from, to, Reuse.Singleton);
return this;
}

/// <summary>
/// Registers a Singleton with the given service and mapping to the specified implementation <see cref="Type" />.
/// </summary>
/// <param name="from">The service <see cref="Type" /></param>
/// <param name="to">The implementation <see cref="Type" /></param>
/// <param name="name">The name or key to register the service</param>
/// <returns>The <see cref="IContainerRegistry" /> instance</returns>
public IContainerRegistry RegisterSingleton(Type from, Type to, string name)
{
Instance.Register(from, to, Reuse.Singleton, serviceKey: name);
return this;
}

/// <summary>
/// Registers a Transient with the given service and mapping to the specified implementation <see cref="Type" />.
/// </summary>
/// <param name="from">The service <see cref="Type" /></param>
/// <param name="to">The implementation <see cref="Type" /></param>
/// <returns>The <see cref="IContainerRegistry" /> instance</returns>
public IContainerRegistry Register(Type from, Type to)
{
Instance.Register(from, to);
return this;
}

/// <summary>
/// Registers a Transient with the given service and mapping to the specified implementation <see cref="Type" />.
/// </summary>
/// <param name="from">The service <see cref="Type" /></param>
/// <param name="to">The implementation <see cref="Type" /></param>
/// <param name="name">The name or key to register the service</param>
/// <returns>The <see cref="IContainerRegistry" /> instance</returns>
public IContainerRegistry Register(Type from, Type to, string name)
{
Instance.Register(from, to, serviceKey: name);
return this;
}

/// <summary>
/// Resolves a given <see cref="Type"/>
/// </summary>
/// <param name="type">The service <see cref="Type"/></param>
/// <returns>The resolved Service <see cref="Type"/></returns>
public object Resolve(Type type)
{
return Instance.Resolve(type);
}

/// <summary>
/// Resolves a given <see cref="Type"/>
/// </summary>
/// <param name="type">The service <see cref="Type"/></param>
/// <param name="name">The service name/key used when registering the <see cref="Type"/></param>
/// <returns>The resolved Service <see cref="Type"/></returns>
public object Resolve(Type type, string name)
{
return Instance.Resolve(type, serviceKey: name);
}

/// <summary>
/// Resolves a given <see cref="Type"/>
/// </summary>
/// <param name="type">The service <see cref="Type"/></param>
/// <param name="parameters">Typed parameters to use when resolving the Service</param>
/// <returns>The resolved Service <see cref="Type"/></returns>
public object Resolve(Type type, params (Type Type, object Instance)[] parameters)
{
return Instance.Resolve(type, args: parameters.Select(p => p.Instance).ToArray());
}

/// <summary>
/// Resolves a given <see cref="Type"/>
/// </summary>
/// <param name="type">The service <see cref="Type"/></param>
/// <param name="name">The service name/key used when registering the <see cref="Type"/></param>
/// <param name="parameters">Typed parameters to use when resolving the Service</param>
/// <returns>The resolved Service <see cref="Type"/></returns>
public object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters)
{
return Instance.Resolve(type, name, args: parameters.Select(p => p.Instance).ToArray());
}

/// <summary>
/// Determines if a given service is registered
/// </summary>
/// <param name="type">The service <see cref="Type" /></param>
/// <returns><c>true</c> if the service is registered.</returns>
public bool IsRegistered(Type type)
{
return Instance.IsRegistered(type);
}

/// <summary>
/// Determines if a given service is registered with the specified name
/// </summary>
/// <param name="type">The service <see cref="Type" /></param>
/// <param name="name">The service name or key used</param>
/// <returns><c>true</c> if the service is registered.</returns>
public bool IsRegistered(Type type, string name)
{
return Instance.IsRegistered(type, name);
}
}
}
15 changes: 15 additions & 0 deletions src/Containers/Prism.DryIoc.Shared/Prism.DryIoc.Shared.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>6e7ec81d-da39-4c4f-a898-0148558c34f4</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Prism.DryIoc</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)DryIocContainerExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PrismIocExtensions.cs" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions src/Containers/Prism.DryIoc.Shared/Prism.DryIoc.Shared.shproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>6e7ec81d-da39-4c4f-a898-0148558c34f4</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Prism.DryIoc.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
31 changes: 31 additions & 0 deletions src/Containers/Prism.DryIoc.Shared/PrismIocExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using DryIoc;
using Prism.Ioc;

namespace Prism.DryIoc
{
/// <summary>
/// Extensions help get the underlying <see cref="IContainer" />
/// </summary>
public static class PrismIocExtensions
{
/// <summary>
/// Gets the <see cref="IContainer" /> from the <see cref="IContainerProvider" />
/// </summary>
/// <param name="containerProvider">The current <see cref="IContainerProvider" /></param>
/// <returns>The underlying <see cref="IContainer" /></returns>
public static IContainer GetContainer(this IContainerProvider containerProvider)
{
return ((IContainerExtension<IContainer>)containerProvider).Instance;
}

/// <summary>
/// Gets the <see cref="IContainer" /> from the <see cref="IContainerProvider" />
/// </summary>
/// <param name="containerRegistry">The current <see cref="IContainerRegistry" /></param>
/// <returns>The underlying <see cref="IContainer" /></returns>
public static IContainer GetContainer(this IContainerRegistry containerRegistry)
{
return ((IContainerExtension<IContainer>)containerRegistry).Instance;
}
}
}
15 changes: 15 additions & 0 deletions src/Containers/Prism.Unity.Shared/Prism.Unity.Shared.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>d66336a6-07e5-401a-a710-daedd6975d59</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Prism.Unity</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)PrismIocExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UnityContainerExtension.cs" />
</ItemGroup>
</Project>
Loading

0 comments on commit d9f7ebe

Please sign in to comment.