Skip to content

Commit

Permalink
Replaced simpleinjector with internal DI (#4)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fw2568 authored Aug 31, 2018
1 parent a6806f8 commit 0a03364
Show file tree
Hide file tree
Showing 28 changed files with 568 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks>
<RootNamespace>Contiva.CloudInit.ConfigDrive</RootNamespace>
<AssemblyName>Contiva.CloudInit.ConfigDrive.Abstractions</AssemblyName>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
6 changes: 0 additions & 6 deletions src/CloudInit.ConfigDrive.Abstractions/Generator/IBuilder.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Contiva.CloudInit.ConfigDrive.Generator
{
public interface IGenerateableBuilder
public interface IGenerateableBuilder : IBuilder
{
void Generate();
}
Expand Down
6 changes: 6 additions & 0 deletions src/CloudInit.ConfigDrive.Abstractions/IBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Contiva.CloudInit.ConfigDrive
{
public interface IBuilder
{
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Contiva.CloudInit.ConfigDrive.Generator
namespace Contiva.CloudInit.ConfigDrive
{
public interface IConfigDriveGenerator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// copyright: rebus-org https://github.com/rebus-org
// source: https://raw.githubusercontent.com/rebus-org/Rebus/master/Rebus/Injection/IResolutionContext.cs

using System.Collections;

namespace Contiva.CloudInit.ConfigDrive.Injection
{
/// <summary>
/// Represents the context of resolving one root service and can be used throughout the tree to fetch something to be injected
/// </summary>
public interface IResolutionContext
{
/// <summary>
/// Gets an instance of the specified <typeparamref name="TService"/>.
/// </summary>
TService Get<TService>();

/// <summary>
/// Gets all instances resolved within this resolution context at this time.
/// </summary>
IEnumerable TrackedInstances { get; }

/// <summary>
/// Gets whether there exists a primary registration for the <typeparamref name="TService"/> type
/// </summary>
bool Has<TService>(bool primary = true);
}
}
47 changes: 47 additions & 0 deletions src/CloudInit.ConfigDrive.Core/BaseBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Contiva.CloudInit.ConfigDrive.Generator;
using Contiva.CloudInit.ConfigDrive.Injection;

namespace Contiva.CloudInit.ConfigDrive
{
public class BaseBuilder: IBuilder
{
private readonly Injectionist _container;
private readonly BaseBuilder _innerBuilder;

protected BaseBuilder(Injectionist container)
{
_container = container;
}

protected BaseBuilder(IBuilder innerBuilder)
{
_innerBuilder = innerBuilder as BaseBuilder;
}

protected Injectionist Container => _container ?? _innerBuilder.Container;


public virtual BaseBuilder With<T>(T instance) where T : class
{
Container.Register(c=> instance);
return this;
}

protected IConfigDriveGenerator Build()
{
PrepareBuild();

if (!Container.Has<IConfigDriveGenerator>())
throw new CloudInitConfigurationException("No Config Drive Generator has been configured");

return Container.Get<IConfigDriveGenerator>().Instance;

}

protected virtual void PrepareBuild()
{
_innerBuilder?.PrepareBuild();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks>
<RootNamespace>Contiva.CloudInit.ConfigDrive</RootNamespace>
<AssemblyName>Contiva.CloudInit.ConfigDrive.Core</AssemblyName>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand All @@ -21,7 +21,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="SimpleInjector" Version="4.3.0" />
<PackageReference Include="YamlDotNet" Version="5.0.1" />
</ItemGroup>

Expand Down
47 changes: 47 additions & 0 deletions src/CloudInit.ConfigDrive.Core/CloudInitConfigurationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
#if NET45
using System.Runtime.Serialization;
#elif NETSTANDARD2_0
using System.Runtime.Serialization;
#endif

namespace Contiva.CloudInit.ConfigDrive
{
#if NET45
[Serializable]
#elif NETSTANDARD2_0
[Serializable]
#endif
public class CloudInitConfigurationException : Exception
{
public CloudInitConfigurationException()
{
}

public CloudInitConfigurationException(string message) : base(message)
{
}

public CloudInitConfigurationException(string message, Exception inner) : base(message, inner)
{
}

#if NET45
/// <summary>
/// Constructs the exception
/// </summary>
public CloudInitConfigurationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#elif NETSTANDARD2_0
/// <summary>
/// Constructs the exception
/// </summary>
public CloudInitConfigurationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endif
}
}
48 changes: 0 additions & 48 deletions src/CloudInit.ConfigDrive.Core/Generator/BaseBuilder.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
namespace Contiva.CloudInit.ConfigDrive.Generator
using Contiva.CloudInit.ConfigDrive.Injection;

namespace Contiva.CloudInit.ConfigDrive.Generator
{
public class GenerateableBuilder : BaseBuilder, IGenerateableBuilder
{
protected GenerateableBuilder(Injectionist container) : base(container)
{

}

protected GenerateableBuilder(IBuilder innerBuilder) : base(innerBuilder)
{
Expand Down
23 changes: 0 additions & 23 deletions src/CloudInit.ConfigDrive.Core/Generator/GeneratorBuilder.cs

This file was deleted.

Loading

0 comments on commit 0a03364

Please sign in to comment.