Skip to content

Commit 07060c7

Browse files
Josh Samuel O. Monrealsohlae
Josh Samuel O. Monreal
authored andcommitted
Created a Composition Root Layer
More details can be found at #20.
1 parent bc1761e commit 07060c7

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

RP.UI/Dependency Injection/UnityConfiguration.cs renamed to RP.CompositionRoot/DependencyInjection.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
using Microsoft.EntityFrameworkCore;
2-
using Microsoft.Extensions.Configuration;
3-
using RP.Business;
1+
using RP.Business;
42
using RP.Business.Core;
53
using RP.DataAccess.RepositoryPattern.Core;
6-
using System.IO;
74
using Unity;
8-
using Unity.Injection;
95
using Unity.Lifetime;
106
using ef = RP.DataAccess.RepositoryPattern.EF;
117
using sp = RP.DataAccess.RepositoryPattern.StoredProcedures;
128

13-
namespace RP.UI.Dependency_Injection
9+
namespace RP.CompositionRoot
1410
{
15-
public class UnityConfiguration
11+
public class DependencyInjection<T>
1612
{
17-
public UnityContainer RegisterDependencies()
13+
private readonly UnityContainer _container;
14+
15+
public DependencyInjection()
16+
{
17+
_container = RegisterDependencies();
18+
}
19+
20+
private UnityContainer RegisterDependencies()
1821
{
1922
var container = new UnityContainer();
2023

@@ -34,5 +37,10 @@ public UnityContainer RegisterDependencies()
3437

3538
return container;
3639
}
40+
41+
public T Resolve()
42+
{
43+
return _container.Resolve<T>();
44+
}
3745
}
3846
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
9+
<PackageReference Include="Unity" Version="5.9.3" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\Data Access Layer\RP.Repository_Pattern\RP.RepositoryPattern.csproj" />
14+
<ProjectReference Include="..\RP.Business\RP.Business.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

RP.UI/Program.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using AutoMapper;
2-
using RP.UI.Dependency_Injection;
2+
using RP.CompositionRoot;
33
using System.Reflection;
4-
using Unity;
54

65
namespace RP.UI
76
{
87
class Program
98
{
109
static void Main(string[] args)
1110
{
12-
var unity = new UnityConfiguration();
13-
var container = unity.RegisterDependencies();
14-
var program = container.Resolve<Initializer>();
11+
var unity = new DependencyInjection<Initializer>();
12+
var program = unity.Resolve();
1513

1614
Mapper.Initialize(config => config.AddProfiles(Assembly.GetExecutingAssembly()));
1715

RP.UI/RP.UI.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Automapper" Version="7.0.1" />
16-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.3" />
17-
<PackageReference Include="Unity" Version="5.8.6" />
1816
</ItemGroup>
1917

2018
<ItemGroup>
2119
<ProjectReference Include="..\RP.Business\RP.Business.csproj" />
20+
<ProjectReference Include="..\RP.CompositionRoot\RP.CompositionRoot.csproj" />
2221
</ItemGroup>
2322

2423
<ItemGroup>

Repository_Pattern.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{79D384D5
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RP.UnitTests", "Tests\RP.UnitTests\RP.UnitTests.csproj", "{267E5359-42B6-4C2F-AE8A-12CE80C722CC}"
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RP.IntegrationTests", "Tests\RP.IntegrationTests\RP.IntegrationTests.csproj", "{B106ACD3-25B3-4829-971C-FCA80924E0C7}"
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RP.IntegrationTests", "Tests\RP.IntegrationTests\RP.IntegrationTests.csproj", "{B106ACD3-25B3-4829-971C-FCA80924E0C7}"
1515
EndProject
1616
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Data Access Layer", "Data Access Layer", "{C5F07335-DF51-44C6-A6EB-629094DF1D8F}"
1717
EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RP.RepositoryPattern", "Data Access Layer\RP.Repository_Pattern\RP.RepositoryPattern.csproj", "{39A21F5C-7EC4-4478-954F-5DED549B96B1}"
1919
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RP.CompositionRoot", "RP.CompositionRoot\RP.CompositionRoot.csproj", "{98941520-C49E-4C1E-A595-A91DF9FABB85}"
21+
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2224
Debug|Any CPU = Debug|Any CPU
@@ -43,6 +45,10 @@ Global
4345
{39A21F5C-7EC4-4478-954F-5DED549B96B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
4446
{39A21F5C-7EC4-4478-954F-5DED549B96B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
4547
{39A21F5C-7EC4-4478-954F-5DED549B96B1}.Release|Any CPU.Build.0 = Release|Any CPU
48+
{98941520-C49E-4C1E-A595-A91DF9FABB85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49+
{98941520-C49E-4C1E-A595-A91DF9FABB85}.Debug|Any CPU.Build.0 = Debug|Any CPU
50+
{98941520-C49E-4C1E-A595-A91DF9FABB85}.Release|Any CPU.ActiveCfg = Release|Any CPU
51+
{98941520-C49E-4C1E-A595-A91DF9FABB85}.Release|Any CPU.Build.0 = Release|Any CPU
4652
EndGlobalSection
4753
GlobalSection(SolutionProperties) = preSolution
4854
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)