Skip to content

Commit 0a03364

Browse files
authored
Replaced simpleinjector with internal DI (#4)
* replaced simpleinjector with internal di container * moved ConfigException * target net 45 directly and add netstandard 1.3 as target * fixed runtime errors with new builder
1 parent a6806f8 commit 0a03364

28 files changed

Lines changed: 568 additions & 124 deletions

src/CloudInit.ConfigDrive.Abstractions/CloudInit.ConfigDrive.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks>
55
<RootNamespace>Contiva.CloudInit.ConfigDrive</RootNamespace>
66
<AssemblyName>Contiva.CloudInit.ConfigDrive.Abstractions</AssemblyName>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

src/CloudInit.ConfigDrive.Abstractions/Generator/IBuilder.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/CloudInit.ConfigDrive.Abstractions/Generator/IGenerateableBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Contiva.CloudInit.ConfigDrive.Generator
22
{
3-
public interface IGenerateableBuilder
3+
public interface IGenerateableBuilder : IBuilder
44
{
55
void Generate();
66
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Contiva.CloudInit.ConfigDrive
2+
{
3+
public interface IBuilder
4+
{
5+
}
6+
}

src/CloudInit.ConfigDrive.Abstractions/Generator/IConfigDriveGenerator.cs renamed to src/CloudInit.ConfigDrive.Abstractions/IConfigDriveGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Contiva.CloudInit.ConfigDrive.Generator
1+
namespace Contiva.CloudInit.ConfigDrive
22
{
33
public interface IConfigDriveGenerator
44
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// copyright: rebus-org https://github.com/rebus-org
2+
// source: https://raw.githubusercontent.com/rebus-org/Rebus/master/Rebus/Injection/IResolutionContext.cs
3+
4+
using System.Collections;
5+
6+
namespace Contiva.CloudInit.ConfigDrive.Injection
7+
{
8+
/// <summary>
9+
/// Represents the context of resolving one root service and can be used throughout the tree to fetch something to be injected
10+
/// </summary>
11+
public interface IResolutionContext
12+
{
13+
/// <summary>
14+
/// Gets an instance of the specified <typeparamref name="TService"/>.
15+
/// </summary>
16+
TService Get<TService>();
17+
18+
/// <summary>
19+
/// Gets all instances resolved within this resolution context at this time.
20+
/// </summary>
21+
IEnumerable TrackedInstances { get; }
22+
23+
/// <summary>
24+
/// Gets whether there exists a primary registration for the <typeparamref name="TService"/> type
25+
/// </summary>
26+
bool Has<TService>(bool primary = true);
27+
}
28+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Contiva.CloudInit.ConfigDrive.Generator;
2+
using Contiva.CloudInit.ConfigDrive.Injection;
3+
4+
namespace Contiva.CloudInit.ConfigDrive
5+
{
6+
public class BaseBuilder: IBuilder
7+
{
8+
private readonly Injectionist _container;
9+
private readonly BaseBuilder _innerBuilder;
10+
11+
protected BaseBuilder(Injectionist container)
12+
{
13+
_container = container;
14+
}
15+
16+
protected BaseBuilder(IBuilder innerBuilder)
17+
{
18+
_innerBuilder = innerBuilder as BaseBuilder;
19+
}
20+
21+
protected Injectionist Container => _container ?? _innerBuilder.Container;
22+
23+
24+
public virtual BaseBuilder With<T>(T instance) where T : class
25+
{
26+
Container.Register(c=> instance);
27+
return this;
28+
}
29+
30+
protected IConfigDriveGenerator Build()
31+
{
32+
PrepareBuild();
33+
34+
if (!Container.Has<IConfigDriveGenerator>())
35+
throw new CloudInitConfigurationException("No Config Drive Generator has been configured");
36+
37+
return Container.Get<IConfigDriveGenerator>().Instance;
38+
39+
}
40+
41+
protected virtual void PrepareBuild()
42+
{
43+
_innerBuilder?.PrepareBuild();
44+
}
45+
}
46+
47+
}

src/CloudInit.ConfigDrive.Core/CloudInit.ConfigDrive.Core.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks>
55
<RootNamespace>Contiva.CloudInit.ConfigDrive</RootNamespace>
66
<AssemblyName>Contiva.CloudInit.ConfigDrive.Core</AssemblyName>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -21,7 +21,6 @@
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
2222
</PackageReference>
2323
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
24-
<PackageReference Include="SimpleInjector" Version="4.3.0" />
2524
<PackageReference Include="YamlDotNet" Version="5.0.1" />
2625
</ItemGroup>
2726

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
#if NET45
3+
using System.Runtime.Serialization;
4+
#elif NETSTANDARD2_0
5+
using System.Runtime.Serialization;
6+
#endif
7+
8+
namespace Contiva.CloudInit.ConfigDrive
9+
{
10+
#if NET45
11+
[Serializable]
12+
#elif NETSTANDARD2_0
13+
[Serializable]
14+
#endif
15+
public class CloudInitConfigurationException : Exception
16+
{
17+
public CloudInitConfigurationException()
18+
{
19+
}
20+
21+
public CloudInitConfigurationException(string message) : base(message)
22+
{
23+
}
24+
25+
public CloudInitConfigurationException(string message, Exception inner) : base(message, inner)
26+
{
27+
}
28+
29+
#if NET45
30+
/// <summary>
31+
/// Constructs the exception
32+
/// </summary>
33+
public CloudInitConfigurationException(SerializationInfo info, StreamingContext context)
34+
: base(info, context)
35+
{
36+
}
37+
#elif NETSTANDARD2_0
38+
/// <summary>
39+
/// Constructs the exception
40+
/// </summary>
41+
public CloudInitConfigurationException(SerializationInfo info, StreamingContext context)
42+
: base(info, context)
43+
{
44+
}
45+
#endif
46+
}
47+
}

src/CloudInit.ConfigDrive.Core/Generator/BaseBuilder.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)