#9: add LightweightIocContainer:

- add factories
- add installer
- fix test
- use factories in client
pull/26/head
Simon Gockner 6 years ago
parent ff6fbfbc67
commit c6376e9d23
  1. 22
      GBase.Client/Factories/IGBaseClientFactory.cs
  2. 29
      GBase.Client/Factories/IGBaseClientSettingsFactory.cs
  3. 24
      GBase.Client/Factories/IGBaseEntryServiceFactory.cs
  4. 24
      GBase.Client/Factories/IGBaseServiceFactory.cs
  5. 24
      GBase.Client/Factories/IGBaseTableServiceFactory.cs
  6. 1
      GBase.Client/GBase.Client.csproj
  7. 81
      GBase.Client/GBase.Client.xml
  8. 13
      GBase.Client/GBaseClient.cs
  9. 41
      GBase.Client/Installers/GBaseClientInstaller.cs
  10. 4
      Test.GBase.Client/IntegrationTest.cs
  11. 1
      Test.GBase.Client/Test.GBase.Client.csproj

@ -0,0 +1,22 @@
// Author: Gockner, Simon
// Created: 2020-02-12
// Copyright(c) 2020 SimonG. All Rights Reserved.
using GBase.Client.Interfaces;
namespace GBase.Client.Factories
{
/// <summary>
/// Factory for the <see cref="IGBaseClient"/>
/// </summary>
public interface IGBaseClientFactory
{
/// <summary>
/// Creates an <see cref="IGBaseClient"/>
/// </summary>
/// <param name="settings">The <see cref="IGBaseClientSettings"/> for this client</param>
/// <returns>A newly created instance of the implementation for <see cref="IGBaseClient"/></returns>
IGBaseClient Create(IGBaseClientSettings settings);
}
}

@ -0,0 +1,29 @@
// Author: Gockner, Simon
// Created: 2020-02-12
// Copyright(c) 2020 SimonG. All Rights Reserved.
using System.Net;
using GBase.Api.Communication;
using GBase.Client.Interfaces;
namespace GBase.Client.Factories
{
/// <summary>
/// Factory for the <see cref="IGBaseClientSettings"/>
/// </summary>
public interface IGBaseClientSettingsFactory
{
/// <summary>
/// Creates an <see cref="IGBaseClientSettings"/>
/// </summary>
/// <param name="protocol">The <see cref="ServerProtocol"/></param>
/// <param name="ipAddress">The <see cref="IPAddress"/></param>
/// <param name="port">The port</param>
/// <param name="gBaseEndpoint">The GBase endpoint</param>
/// <param name="gBaseTableEndpoint">The GBaseTable endpoint</param>
/// <param name="gBaseEntryEndpoint">The GBaseEntry endpoint</param>
/// <returns>A newly created instance of the implementation for <see cref="IGBaseClientSettings"/></returns>
IGBaseClientSettings Create(ServerProtocol protocol, IPAddress ipAddress, int port, string gBaseEndpoint, string gBaseTableEndpoint, string gBaseEntryEndpoint);
}
}

@ -0,0 +1,24 @@
// Author: Gockner, Simon
// Created: 2020-02-12
// Copyright(c) 2020 SimonG. All Rights Reserved.
using GBase.Api.Communication;
using GBase.Api.Services;
namespace GBase.Client.Factories
{
/// <summary>
/// Factory for the <see cref="IGBaseEntryService"/>
/// </summary>
public interface IGBaseEntryServiceFactory
{
/// <summary>
/// Creates an <see cref="IGBaseEntryService"/>
/// </summary>
/// <param name="serverProtocol">The <see cref="ServerProtocol"/></param>
/// <param name="endpoint">The endpoint for the GBase</param>
/// <returns>A newly created instance of the implementation for <see cref="IGBaseEntryService"/></returns>
IGBaseEntryService Create(ServerProtocol serverProtocol, string endpoint);
}
}

@ -0,0 +1,24 @@
// Author: Gockner, Simon
// Created: 2020-02-12
// Copyright(c) 2020 SimonG. All Rights Reserved.
using GBase.Api.Communication;
using GBase.Api.Services;
namespace GBase.Client.Factories
{
/// <summary>
/// Factory for the <see cref="IGBaseService"/>
/// </summary>
public interface IGBaseServiceFactory
{
/// <summary>
/// Creates an <see cref="IGBaseService"/>
/// </summary>
/// <param name="serverProtocol">The <see cref="ServerProtocol"/></param>
/// <param name="endpoint">The endpoint for the GBase</param>
/// <returns>A newly created instance of the implementation for <see cref="IGBaseService"/></returns>
IGBaseService Create(ServerProtocol serverProtocol, string endpoint);
}
}

@ -0,0 +1,24 @@
// Author: Gockner, Simon
// Created: 2020-02-12
// Copyright(c) 2020 SimonG. All Rights Reserved.
using GBase.Api.Communication;
using GBase.Api.Services;
namespace GBase.Client.Factories
{
/// <summary>
/// Factory for the <see cref="IGBaseTableService"/>
/// </summary>
public interface IGBaseTableServiceFactory
{
/// <summary>
/// Creates an <see cref="IGBaseTableService"/>
/// </summary>
/// <param name="serverProtocol">The <see cref="ServerProtocol"/></param>
/// <param name="endpoint">The endpoint for the GBase</param>
/// <returns>A newly created instance of the implementation for <see cref="IGBaseTableService"/></returns>
IGBaseTableService Create(ServerProtocol serverProtocol, string endpoint);
}
}

@ -27,6 +27,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="LightweightIocContainer" Version="2.1.0" />
<PackageReference Include="System.ServiceModel.Http" Version="4.7.0" /> <PackageReference Include="System.ServiceModel.Http" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.7.0" /> <PackageReference Include="System.ServiceModel.NetTcp" Version="4.7.0" />
</ItemGroup> </ItemGroup>

@ -4,16 +4,87 @@
<name>GBase.Client</name> <name>GBase.Client</name>
</assembly> </assembly>
<members> <members>
<member name="T:GBase.Client.Factories.IGBaseClientFactory">
<summary>
Factory for the <see cref="T:GBase.Client.Interfaces.IGBaseClient"/>
</summary>
</member>
<member name="M:GBase.Client.Factories.IGBaseClientFactory.Create(GBase.Client.Interfaces.IGBaseClientSettings)">
<summary>
Creates an <see cref="T:GBase.Client.Interfaces.IGBaseClient"/>
</summary>
<param name="settings">The <see cref="T:GBase.Client.Interfaces.IGBaseClientSettings"/> for this client</param>
<returns>A newly created instance of the implementation for <see cref="T:GBase.Client.Interfaces.IGBaseClient"/></returns>
</member>
<member name="T:GBase.Client.Factories.IGBaseClientSettingsFactory">
<summary>
Factory for the <see cref="T:GBase.Client.Interfaces.IGBaseClientSettings"/>
</summary>
</member>
<member name="M:GBase.Client.Factories.IGBaseClientSettingsFactory.Create(GBase.Api.Communication.ServerProtocol,System.Net.IPAddress,System.Int32,System.String,System.String,System.String)">
<summary>
Creates an <see cref="T:GBase.Client.Interfaces.IGBaseClientSettings"/>
</summary>
<param name="protocol">The <see cref="T:GBase.Api.Communication.ServerProtocol"/></param>
<param name="ipAddress">The <see cref="T:System.Net.IPAddress"/></param>
<param name="port">The port</param>
<param name="gBaseEndpoint">The GBase endpoint</param>
<param name="gBaseTableEndpoint">The GBaseTable endpoint</param>
<param name="gBaseEntryEndpoint">The GBaseEntry endpoint</param>
<returns>A newly created instance of the implementation for <see cref="T:GBase.Client.Interfaces.IGBaseClientSettings"/></returns>
</member>
<member name="T:GBase.Client.Factories.IGBaseEntryServiceFactory">
<summary>
Factory for the <see cref="T:GBase.Api.Services.IGBaseEntryService"/>
</summary>
</member>
<member name="M:GBase.Client.Factories.IGBaseEntryServiceFactory.Create(GBase.Api.Communication.ServerProtocol,System.String)">
<summary>
Creates an <see cref="T:GBase.Api.Services.IGBaseEntryService"/>
</summary>
<param name="serverProtocol">The <see cref="T:GBase.Api.Communication.ServerProtocol"/></param>
<param name="endpoint">The endpoint for the GBase</param>
<returns>A newly created instance of the implementation for <see cref="T:GBase.Api.Services.IGBaseEntryService"/></returns>
</member>
<member name="T:GBase.Client.Factories.IGBaseServiceFactory">
<summary>
Factory for the <see cref="T:GBase.Api.Services.IGBaseService"/>
</summary>
</member>
<member name="M:GBase.Client.Factories.IGBaseServiceFactory.Create(GBase.Api.Communication.ServerProtocol,System.String)">
<summary>
Creates an <see cref="T:GBase.Api.Services.IGBaseService"/>
</summary>
<param name="serverProtocol">The <see cref="T:GBase.Api.Communication.ServerProtocol"/></param>
<param name="endpoint">The endpoint for the GBase</param>
<returns>A newly created instance of the implementation for <see cref="T:GBase.Api.Services.IGBaseService"/></returns>
</member>
<member name="T:GBase.Client.Factories.IGBaseTableServiceFactory">
<summary>
Factory for the <see cref="T:GBase.Api.Services.IGBaseTableService"/>
</summary>
</member>
<member name="M:GBase.Client.Factories.IGBaseTableServiceFactory.Create(GBase.Api.Communication.ServerProtocol,System.String)">
<summary>
Creates an <see cref="T:GBase.Api.Services.IGBaseTableService"/>
</summary>
<param name="serverProtocol">The <see cref="T:GBase.Api.Communication.ServerProtocol"/></param>
<param name="endpoint">The endpoint for the GBase</param>
<returns>A newly created instance of the implementation for <see cref="T:GBase.Api.Services.IGBaseTableService"/></returns>
</member>
<member name="T:GBase.Client.GBaseClient"> <member name="T:GBase.Client.GBaseClient">
<summary> <summary>
A client for the GBase A client for the GBase
</summary> </summary>
</member> </member>
<member name="M:GBase.Client.GBaseClient.#ctor(GBase.Client.Interfaces.IGBaseClientSettings)"> <member name="M:GBase.Client.GBaseClient.#ctor(GBase.Client.Interfaces.IGBaseClientSettings,GBase.Client.Factories.IGBaseServiceFactory,GBase.Client.Factories.IGBaseTableServiceFactory,GBase.Client.Factories.IGBaseEntryServiceFactory)">
<summary> <summary>
A client for the GBase A client for the GBase
</summary> </summary>
<param name="settings">The <see cref="T:GBase.Client.Interfaces.IGBaseClientSettings"/> for this client</param> <param name="settings">The <see cref="T:GBase.Client.Interfaces.IGBaseClientSettings"/> for this client</param>
<param name="gBaseServiceFactory">The <see cref="T:GBase.Client.Factories.IGBaseServiceFactory"/></param>
<param name="gBaseTableServiceFactory">The <see cref="T:GBase.Client.Factories.IGBaseTableServiceFactory"/></param>
<param name="gBaseEntryServiceFactory">The <see cref="T:GBase.Client.Factories.IGBaseEntryServiceFactory"/></param>
</member> </member>
<member name="P:GBase.Client.GBaseClient.GBase"> <member name="P:GBase.Client.GBaseClient.GBase">
<summary> <summary>
@ -97,6 +168,14 @@
Complete GBaseEntry endpoint address based on the <see cref="T:GBase.Api.Communication.ICommunicationSettings"/> Complete GBaseEntry endpoint address based on the <see cref="T:GBase.Api.Communication.ICommunicationSettings"/>
</summary> </summary>
</member> </member>
<member name="T:GBase.Client.Installers.GBaseClientInstaller">
<summary>
<see cref="T:LightweightIocContainer.Interfaces.Installers.IIocInstaller"/> for the <see cref="T:GBase.Client.GBaseClient"/>
</summary>
</member>
<member name="M:GBase.Client.Installers.GBaseClientInstaller.Install(LightweightIocContainer.Interfaces.IIocContainer)">
<inheritdoc />
</member>
<member name="T:GBase.Client.Interfaces.IGBaseClient"> <member name="T:GBase.Client.Interfaces.IGBaseClient">
<summary> <summary>
A client for the GBase A client for the GBase

@ -4,8 +4,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using GBase.Api.Services; using GBase.Api.Services;
using GBase.Client.Factories;
using GBase.Client.Interfaces; using GBase.Client.Interfaces;
using GBase.Client.Services;
namespace GBase.Client namespace GBase.Client
{ {
@ -18,11 +18,14 @@ namespace GBase.Client
/// A client for the GBase /// A client for the GBase
/// </summary> /// </summary>
/// <param name="settings">The <see cref="IGBaseClientSettings"/> for this client</param> /// <param name="settings">The <see cref="IGBaseClientSettings"/> for this client</param>
public GBaseClient(IGBaseClientSettings settings) /// <param name="gBaseServiceFactory">The <see cref="IGBaseServiceFactory"/></param>
/// <param name="gBaseTableServiceFactory">The <see cref="IGBaseTableServiceFactory"/></param>
/// <param name="gBaseEntryServiceFactory">The <see cref="IGBaseEntryServiceFactory"/></param>
public GBaseClient(IGBaseClientSettings settings, IGBaseServiceFactory gBaseServiceFactory, IGBaseTableServiceFactory gBaseTableServiceFactory, IGBaseEntryServiceFactory gBaseEntryServiceFactory)
{ {
GBase = new GBaseService(settings.Protocol, settings.ServerProtocolGBaseEndpointAddress); GBase = gBaseServiceFactory.Create(settings.Protocol, settings.ServerProtocolGBaseEndpointAddress);
GBaseTable = new GBaseTableService(settings.Protocol, settings.ServerProtocolGBaseTableEndpointAddress); GBaseTable = gBaseTableServiceFactory.Create(settings.Protocol, settings.ServerProtocolGBaseTableEndpointAddress);
GBaseEntry = new GBaseEntryService(settings.Protocol, settings.ServerProtocolGBaseEntryEndpointAddress); GBaseEntry = gBaseEntryServiceFactory.Create(settings.Protocol, settings.ServerProtocolGBaseEntryEndpointAddress);
} }
/// <summary> /// <summary>

@ -0,0 +1,41 @@
// Author: Gockner, Simon
// Created: 2020-02-12
// Copyright(c) 2020 SimonG. All Rights Reserved.
using GBase.Api.Services;
using GBase.Client.Factories;
using GBase.Client.Interfaces;
using GBase.Client.Services;
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Installers;
namespace GBase.Client.Installers
{
/// <summary>
/// <see cref="IIocInstaller"/> for the <see cref="GBaseClient"/>
/// </summary>
public class GBaseClientInstaller : IIocInstaller
{
/// <inheritdoc />
public void Install(IIocContainer container)
{
container.Register<IGBaseClient, GBaseClient>();
container.Register<IGBaseClientSettings, GBaseClientSettings>();
//services
container.Register<IGBaseService, GBaseService>();
container.Register<IGBaseTableService, GBaseTableService>();
container.Register<IGBaseEntryService, GBaseEntryService>();
//factories
container.RegisterFactory<IGBaseClientFactory>();
container.RegisterFactory<IGBaseClientSettingsFactory>();
//service factories
container.RegisterFactory<IGBaseServiceFactory>();
container.RegisterFactory<IGBaseTableServiceFactory>();
container.RegisterFactory<IGBaseEntryServiceFactory>();
}
}
}

@ -1,7 +1,9 @@
using System.Net; using System.Net;
using GBase.Api.Communication; using GBase.Api.Communication;
using GBase.Client; using GBase.Client;
using GBase.Client.Factories;
using GBase.Client.Interfaces; using GBase.Client.Interfaces;
using Moq;
using NUnit.Framework; using NUnit.Framework;
namespace Test.GBase.Client namespace Test.GBase.Client
@ -21,7 +23,7 @@ namespace Test.GBase.Client
IGBaseClientSettings settings = IGBaseClientSettings settings =
new GBaseClientSettings(ServerProtocol.Http, IPAddress.Parse("127.0.0.1"), 8080, "/GBase", "/GBaseTable", "/GBaseEntry"); new GBaseClientSettings(ServerProtocol.Http, IPAddress.Parse("127.0.0.1"), 8080, "/GBase", "/GBaseTable", "/GBaseEntry");
IGBaseClient client = new GBaseClient(settings); IGBaseClient client = new GBaseClient(settings, new Mock<IGBaseServiceFactory>().Object, new Mock<IGBaseTableServiceFactory>().Object, new Mock<IGBaseEntryServiceFactory>().Object);
bool ret = client.GBase.AddTable(); bool ret = client.GBase.AddTable();
Assert.True(ret); Assert.True(ret);

@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="nunit" Version="3.12.0" /> <PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"> <PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>

Loading…
Cancel
Save