diff --git a/src/CloudInit.ConfigDrive.Abstractions/CloudInit.ConfigDrive.Abstractions.csproj b/src/CloudInit.ConfigDrive.Abstractions/CloudInit.ConfigDrive.Abstractions.csproj index a1c0be0..414cf99 100644 --- a/src/CloudInit.ConfigDrive.Abstractions/CloudInit.ConfigDrive.Abstractions.csproj +++ b/src/CloudInit.ConfigDrive.Abstractions/CloudInit.ConfigDrive.Abstractions.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net45;netstandard1.3;netstandard2.0 Contiva.CloudInit.ConfigDrive Contiva.CloudInit.ConfigDrive.Abstractions true diff --git a/src/CloudInit.ConfigDrive.Abstractions/Generator/IBuilder.cs b/src/CloudInit.ConfigDrive.Abstractions/Generator/IBuilder.cs deleted file mode 100644 index 9d480b4..0000000 --- a/src/CloudInit.ConfigDrive.Abstractions/Generator/IBuilder.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Contiva.CloudInit.ConfigDrive.Generator -{ - public interface IBuilder - { - } -} \ No newline at end of file diff --git a/src/CloudInit.ConfigDrive.Abstractions/Generator/IGenerateableBuilder.cs b/src/CloudInit.ConfigDrive.Abstractions/Generator/IGenerateableBuilder.cs index 6e55d98..7504786 100644 --- a/src/CloudInit.ConfigDrive.Abstractions/Generator/IGenerateableBuilder.cs +++ b/src/CloudInit.ConfigDrive.Abstractions/Generator/IGenerateableBuilder.cs @@ -1,6 +1,6 @@ namespace Contiva.CloudInit.ConfigDrive.Generator { - public interface IGenerateableBuilder + public interface IGenerateableBuilder : IBuilder { void Generate(); } diff --git a/src/CloudInit.ConfigDrive.Abstractions/IBuilder.cs b/src/CloudInit.ConfigDrive.Abstractions/IBuilder.cs new file mode 100644 index 0000000..738df4b --- /dev/null +++ b/src/CloudInit.ConfigDrive.Abstractions/IBuilder.cs @@ -0,0 +1,6 @@ +namespace Contiva.CloudInit.ConfigDrive +{ + public interface IBuilder + { + } +} \ No newline at end of file diff --git a/src/CloudInit.ConfigDrive.Abstractions/Generator/IConfigDriveGenerator.cs b/src/CloudInit.ConfigDrive.Abstractions/IConfigDriveGenerator.cs similarity index 61% rename from src/CloudInit.ConfigDrive.Abstractions/Generator/IConfigDriveGenerator.cs rename to src/CloudInit.ConfigDrive.Abstractions/IConfigDriveGenerator.cs index 2073ffe..f628178 100644 --- a/src/CloudInit.ConfigDrive.Abstractions/Generator/IConfigDriveGenerator.cs +++ b/src/CloudInit.ConfigDrive.Abstractions/IConfigDriveGenerator.cs @@ -1,4 +1,4 @@ -namespace Contiva.CloudInit.ConfigDrive.Generator +namespace Contiva.CloudInit.ConfigDrive { public interface IConfigDriveGenerator { diff --git a/src/CloudInit.ConfigDrive.Abstractions/Injection/IResolutionContext.cs b/src/CloudInit.ConfigDrive.Abstractions/Injection/IResolutionContext.cs new file mode 100644 index 0000000..03b8c8b --- /dev/null +++ b/src/CloudInit.ConfigDrive.Abstractions/Injection/IResolutionContext.cs @@ -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 +{ + /// + /// Represents the context of resolving one root service and can be used throughout the tree to fetch something to be injected + /// + public interface IResolutionContext + { + /// + /// Gets an instance of the specified . + /// + TService Get(); + + /// + /// Gets all instances resolved within this resolution context at this time. + /// + IEnumerable TrackedInstances { get; } + + /// + /// Gets whether there exists a primary registration for the type + /// + bool Has(bool primary = true); + } +} \ No newline at end of file diff --git a/src/CloudInit.ConfigDrive.Core/BaseBuilder.cs b/src/CloudInit.ConfigDrive.Core/BaseBuilder.cs new file mode 100644 index 0000000..67436b5 --- /dev/null +++ b/src/CloudInit.ConfigDrive.Core/BaseBuilder.cs @@ -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 instance) where T : class + { + Container.Register(c=> instance); + return this; + } + + protected IConfigDriveGenerator Build() + { + PrepareBuild(); + + if (!Container.Has()) + throw new CloudInitConfigurationException("No Config Drive Generator has been configured"); + + return Container.Get().Instance; + + } + + protected virtual void PrepareBuild() + { + _innerBuilder?.PrepareBuild(); + } + } + +} \ No newline at end of file diff --git a/src/CloudInit.ConfigDrive.Core/CloudInit.ConfigDrive.Core.csproj b/src/CloudInit.ConfigDrive.Core/CloudInit.ConfigDrive.Core.csproj index c4a7380..aa6d9d8 100644 --- a/src/CloudInit.ConfigDrive.Core/CloudInit.ConfigDrive.Core.csproj +++ b/src/CloudInit.ConfigDrive.Core/CloudInit.ConfigDrive.Core.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net45;netstandard1.3;netstandard2.0 Contiva.CloudInit.ConfigDrive Contiva.CloudInit.ConfigDrive.Core true @@ -21,7 +21,6 @@ runtime; build; native; contentfiles; analyzers - diff --git a/src/CloudInit.ConfigDrive.Core/CloudInitConfigurationException.cs b/src/CloudInit.ConfigDrive.Core/CloudInitConfigurationException.cs new file mode 100644 index 0000000..c989dd3 --- /dev/null +++ b/src/CloudInit.ConfigDrive.Core/CloudInitConfigurationException.cs @@ -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 +/// +/// Constructs the exception +/// + public CloudInitConfigurationException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } +#elif NETSTANDARD2_0 +/// +/// Constructs the exception +/// + public CloudInitConfigurationException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } +#endif + } +} \ No newline at end of file diff --git a/src/CloudInit.ConfigDrive.Core/Generator/BaseBuilder.cs b/src/CloudInit.ConfigDrive.Core/Generator/BaseBuilder.cs deleted file mode 100644 index 7d7dfc6..0000000 --- a/src/CloudInit.ConfigDrive.Core/Generator/BaseBuilder.cs +++ /dev/null @@ -1,48 +0,0 @@ -using SimpleInjector; - -namespace Contiva.CloudInit.ConfigDrive.Generator -{ - public class BaseBuilder: IBuilder - { - private readonly Container _container; - private readonly BaseBuilder _innerBuilder; - - protected BaseBuilder(Container container) - { - _container = container; - } - - protected BaseBuilder(IBuilder innerBuilder) - { - _innerBuilder = innerBuilder as BaseBuilder; - } - - protected Container Container => _container ?? _innerBuilder.Container; - - - public virtual BaseBuilder With(T instance) where T : class - { - Container.RegisterInstance(instance); - return this; - } - - protected IConfigDriveGenerator Build() - { - PrepareBuild(); - - Container.RegisterConditional(c => !c.Handled); - Container.RegisterConditional(typeof(ICommandHandler<>), typeof(DummyCommandHandler<>), c => !c.Handled); - - Container.Verify(); - - return Container.GetInstance(); - - } - - - protected virtual void PrepareBuild() - { - _innerBuilder?.PrepareBuild(); - } - } -} \ No newline at end of file diff --git a/src/CloudInit.ConfigDrive.Core/Generator/GeneratableBuilder.cs b/src/CloudInit.ConfigDrive.Core/Generator/GeneratableBuilder.cs index e5d4117..782385c 100644 --- a/src/CloudInit.ConfigDrive.Core/Generator/GeneratableBuilder.cs +++ b/src/CloudInit.ConfigDrive.Core/Generator/GeneratableBuilder.cs @@ -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) { diff --git a/src/CloudInit.ConfigDrive.Core/Generator/GeneratorBuilder.cs b/src/CloudInit.ConfigDrive.Core/Generator/GeneratorBuilder.cs deleted file mode 100644 index 4e73be1..0000000 --- a/src/CloudInit.ConfigDrive.Core/Generator/GeneratorBuilder.cs +++ /dev/null @@ -1,23 +0,0 @@ -using SimpleInjector; - -namespace Contiva.CloudInit.ConfigDrive.Generator -{ - - public class GeneratorBuilder : BaseBuilder - { - - public static GeneratorBuilder Init() - { - var container = new Container(); - return new GeneratorBuilder(container); - } - - protected GeneratorBuilder(Container container) : base(container) - { - } - - protected GeneratorBuilder(BaseBuilder innerBuilder): base(innerBuilder) - { - } - } -} diff --git a/src/CloudInit.ConfigDrive.Core/Injection/Injectionist.cs b/src/CloudInit.ConfigDrive.Core/Injection/Injectionist.cs new file mode 100644 index 0000000..f3c71ec --- /dev/null +++ b/src/CloudInit.ConfigDrive.Core/Injection/Injectionist.cs @@ -0,0 +1,262 @@ +// copyright: rebus-org https://github.com/rebus-org +// source: https://raw.githubusercontent.com/rebus-org/Rebus/master/Rebus/Injection/Injectionist.cs + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Contiva.CloudInit.ConfigDrive.Injection +{ + /// + /// Dependency injectionist that can be used for configuring a system of injected service implementations, possibly with decorators, + /// with caching of instances so that the same instance of each class is used throughout the tree. Should probably not be used for + /// anything at runtime, is only meant to be used in configuration scenarios. + /// + public class Injectionist + { + class Handler + { + public Handler() + { + Decorators = new List(); + } + + public Resolver PrimaryResolver { get; private set; } + + public List Decorators { get; private set; } + + void AddDecorator(Resolver resolver) + { + Decorators.Insert(0, resolver); + } + + public void AddResolver(Resolver resolver) + { + if (!resolver.IsDecorator) + { + AddPrimary(resolver); + } + else + { + AddDecorator(resolver); + } + } + + void AddPrimary(Resolver resolver) + { + PrimaryResolver = resolver; + } + } + + readonly Dictionary _resolvers = new Dictionary(); + + /// + /// Starts a new resolution context, resolving an instance of the given + /// + public ResolutionResult Get() + { + var resolutionContext = new ResolutionContext(_resolvers, ResolveRequested); + var instance = resolutionContext.Get(); + return new ResolutionResult(instance, resolutionContext.TrackedInstances); + } + + /// + /// Events that is raised when the resolution of a top-level instance is requested + /// + public event Action ResolveRequested = delegate { }; + + /// + /// Registers a factory method that can provide an instance of . Optionally, + /// the supplied will be used to report more comprehensible errors in case of + /// conflicting registrations. + /// + public void Register(Func resolverMethod, string description = null) + { + Register(resolverMethod, description: description, isDecorator: false); + } + + /// + /// Registers a decorator factory method that can provide an instance of + /// (i.e. the resolver is expected to call where TService + /// is . Optionally, the supplied will be used + /// to report more comprehensible errors in case of conflicting registrations. + /// + public void Decorate(Func resolverMethod, string description = null) + { + Register(resolverMethod, description: description, isDecorator: true); + } + + /// + /// Returns whether there exists a registration for the specified . + /// + public bool Has(bool primary = true) + { + return ResolverHaveRegistrationFor(primary, _resolvers); + } + + static bool ResolverHaveRegistrationFor(bool primary, Dictionary resolvers) + { + var key = typeof(TService); + + if (!resolvers.ContainsKey(key)) return false; + + var handler = resolvers[key]; + + if (handler.PrimaryResolver != null) return true; + + if (!primary && handler.Decorators.Any()) return true; + + return false; + } + + void Register(Func resolverMethod, bool isDecorator, string description) + { + var handler = GetOrCreateHandler(); + var resolver = new Resolver(resolverMethod, description: description, isDecorator: isDecorator); + + if (!isDecorator) + { + if (handler.PrimaryResolver != null) + { + var message = $"Attempted to register {resolver}, but a primary registration already exists: {handler.PrimaryResolver}"; + + throw new InvalidOperationException(message); + } + } + + handler.AddResolver(resolver); + } + + Handler GetOrCreateHandler() + { + Handler handler; + + if (_resolvers.TryGetValue(typeof(TService), out handler)) return handler; + + handler = new Handler(); + _resolvers[typeof(TService)] = handler; + + return handler; + } + + abstract class Resolver + { + protected Resolver(bool isDecorator) + { + IsDecorator = isDecorator; + } + + public bool IsDecorator { get; private set; } + } + + class Resolver : Resolver + { + readonly Func _resolver; + readonly string _description; + + public Resolver(Func resolver, bool isDecorator, string description) + : base(isDecorator) + { + _resolver = resolver; + _description = description; + } + + public TService InvokeResolver(IResolutionContext context) + { + return _resolver(context); + } + + public override string ToString() + { + var role = IsDecorator ? "decorator ->" : "primary ->"; + var type = typeof(TService); + + return !string.IsNullOrWhiteSpace(_description) + ? $"{role} {type} ({_description})" + : $"{role} {type}"; + } + } + + class ResolutionContext : IResolutionContext + { + readonly Dictionary _decoratorDepth = new Dictionary(); + readonly Dictionary _resolvers; + readonly Action _serviceTypeRequested; + readonly Dictionary _instances = new Dictionary(); + readonly List _resolvedInstances = new List(); + + public ResolutionContext(Dictionary resolvers, Action serviceTypeRequested) + { + _resolvers = resolvers; + _serviceTypeRequested = serviceTypeRequested; + } + + public bool Has(bool primary = true) + { + return ResolverHaveRegistrationFor(primary, _resolvers); + } + + public TService Get() + { + var serviceType = typeof(TService); + + object existingInstance; + + if (_instances.TryGetValue(serviceType, out existingInstance)) + { + return (TService)existingInstance; + } + + if (!_resolvers.ContainsKey(serviceType)) + { + throw new ResolutionException($"Could not find resolver for {serviceType}"); + } + + if (!_decoratorDepth.ContainsKey(serviceType)) + { + _decoratorDepth[serviceType] = 0; + _serviceTypeRequested(serviceType); + } + + var handlerForThisType = _resolvers[serviceType]; + var depth = _decoratorDepth[serviceType]++; + + try + { + var resolver = handlerForThisType + .Decorators + .Cast>() + .Skip(depth) + .FirstOrDefault() + ?? (Resolver)handlerForThisType.PrimaryResolver; + + var instance = resolver.InvokeResolver(this); + + _instances[serviceType] = instance; + + if (!_resolvedInstances.Contains(instance)) + { + _resolvedInstances.Add(instance); + } + + return instance; + } + catch (ResolutionException) + { + throw; //< let this one through + } + catch (Exception exception) + { + throw new ResolutionException(exception, $"Could not resolve {serviceType} with decorator depth {depth} - registrations: {string.Join("; ", handlerForThisType)}"); + } + finally + { + _decoratorDepth[serviceType]--; + } + } + + public IEnumerable TrackedInstances => _resolvedInstances.ToList(); + } + } +} \ No newline at end of file diff --git a/src/CloudInit.ConfigDrive.Core/Injection/ResolutionException.cs b/src/CloudInit.ConfigDrive.Core/Injection/ResolutionException.cs new file mode 100644 index 0000000..1e443ec --- /dev/null +++ b/src/CloudInit.ConfigDrive.Core/Injection/ResolutionException.cs @@ -0,0 +1,57 @@ +// copyright: rebus-org https://github.com/rebus-org +// source: https://raw.githubusercontent.com/rebus-org/Rebus/master/Rebus/Injection/ResolutionException.cs + +using System; +#if NET45 +using System.Runtime.Serialization; +#elif NETSTANDARD2_0 +using System.Runtime.Serialization; +#endif + +namespace Contiva.CloudInit.ConfigDrive.Injection +{ + /// + /// Exceptions that is thrown when something goes wrong while working with the injectionist + /// +#if NET45 + [Serializable] +#elif NETSTANDARD2_0 + [Serializable] +#endif + public class ResolutionException : Exception + { + /// + /// Constructs the exception + /// + public ResolutionException(string message) + : base(message) + { + } + + /// + /// Constructs the exception + /// + public ResolutionException(Exception innerException, string message) + : base(message, innerException) + { + } + +#if NET45 +/// +/// Constructs the exception +/// + public ResolutionException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } +#elif NETSTANDARD2_0 + /// + /// Constructs the exception + /// + public ResolutionException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } +#endif + } +} \ No newline at end of file diff --git a/src/CloudInit.ConfigDrive.Core/Injection/ResolutionResult.cs b/src/CloudInit.ConfigDrive.Core/Injection/ResolutionResult.cs new file mode 100644 index 0000000..e0ecd17 --- /dev/null +++ b/src/CloudInit.ConfigDrive.Core/Injection/ResolutionResult.cs @@ -0,0 +1,31 @@ +// copyright: rebus-org https://github.com/rebus-org +// source: https://raw.githubusercontent.com/rebus-org/Rebus/master/Rebus/Injection/ResolutionResult.cs + +using System; +using System.Collections; + +namespace Contiva.CloudInit.ConfigDrive.Injection +{ + /// + /// Contains a built object instance along with all the objects that were used to build the instance + /// + public class ResolutionResult + { + internal ResolutionResult(TService instance, IEnumerable trackedInstances) + { + if (instance == null) throw new ArgumentNullException(nameof(instance)); + Instance = instance; + TrackedInstances = trackedInstances ?? throw new ArgumentNullException(nameof(trackedInstances)); + } + + /// + /// Gets the instance that was built + /// + public TService Instance { get; } + + /// + /// Gets all object instances that were used to build , including the instance itself + /// + public IEnumerable TrackedInstances { get; } + } +} \ No newline at end of file diff --git a/src/CloudInit.ConfigDrive.Core/Processing/ProcessorBuilder.cs b/src/CloudInit.ConfigDrive.Core/Processing/ProcessorBuilder.cs index 05ac755..bec0f32 100644 --- a/src/CloudInit.ConfigDrive.Core/Processing/ProcessorBuilder.cs +++ b/src/CloudInit.ConfigDrive.Core/Processing/ProcessorBuilder.cs @@ -12,9 +12,9 @@ public ProcessorBuilder(IBuilder innerBuilder) : base(innerBuilder) public ProcessorBuilder Callback(Action contentAction) { Container - .RegisterDecorator, CallbackProcessResultCommandHandlerDecoration>(); - Container.RegisterInitializer( - s => s.ContentAction = contentAction); + .Decorate>( + c=> new CallbackProcessResultCommandHandlerDecoration( + c.Get>()) {ContentAction = contentAction}); return this; } diff --git a/src/CloudInit.ConfigDrive.NoCloud/CloudInit.ConfigDrive.NoCloud.csproj b/src/CloudInit.ConfigDrive.NoCloud/CloudInit.ConfigDrive.NoCloud.csproj index 066ed1b..9fb6273 100644 --- a/src/CloudInit.ConfigDrive.NoCloud/CloudInit.ConfigDrive.NoCloud.csproj +++ b/src/CloudInit.ConfigDrive.NoCloud/CloudInit.ConfigDrive.NoCloud.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net45;netstandard1.3;netstandard2.0 Contiva.CloudInit.ConfigDrive.NoCloud Contiva.CloudInit.ConfigDrive true diff --git a/src/CloudInit.ConfigDrive.NoCloud/NoCloud/NoCloudGeneratorBuilder.cs b/src/CloudInit.ConfigDrive.NoCloud/NoCloud/NoCloudGeneratorBuilder.cs index 58e1629..2d57689 100644 --- a/src/CloudInit.ConfigDrive.NoCloud/NoCloud/NoCloudGeneratorBuilder.cs +++ b/src/CloudInit.ConfigDrive.NoCloud/NoCloud/NoCloudGeneratorBuilder.cs @@ -8,48 +8,46 @@ public class NoCloudGeneratorBuilder : GenerateableBuilder, IProcessableBuilder { internal NoCloudGeneratorBuilder(IBuilder innerBuilder) : base(innerBuilder) { - Container.Register, NoCloudGenerateResultCommandHandler>(); + Container.Register>( + c=> new NoCloudGenerateResultCommandHandler( + c.Get>(), + c.Get>(), + c.Get>())); - Container.Register, GenerateMetaDataCommandHandler>(); - Container.RegisterInitializer< GenerateMetaDataCommandHandler>(h => h.Metadata = Metadata); + Container.Register>( + c=> new GenerateMetaDataCommandHandler{ Metadata = Metadata}); - Container.Register, GenerateUserDataCommandHandler>(); - Container.RegisterInitializer(h => h.UserData = _userData); + Container.Register>( + c => new GenerateUserDataCommandHandler { UserData = _userData }); - Container.Register, GenerateNetworkDataCommandHandler>(); - Container.RegisterInitializer(h => h.NetworkData = _networkData); + Container.Register>( + c => new GenerateNetworkDataCommandHandler { NetworkData = _networkData }); } public NoCloudGeneratorBuilder SwapFile(string filename = "/swap.img", string size = "auto") { - Container.RegisterDecorator, GenerateSwapConfigCommandHandlerDecorator>(); - Container.RegisterInitializer(h => - { - h.Filename = filename; - h.Size = size; - }); + Container.Decorate>( + c => new GenerateSwapConfigCommandHandlerDecorator( + c.Get>()){ Filename = filename, Size = size}); + return this; } public NoCloudGeneratorBuilder Content(string filename) { - Container.RegisterDecorator, GenerateContentConfigCommandHandlerDecorator>(); - Container.RegisterInitializer(h => - { - h.Filename = filename; + Container.Decorate>(c => + new GenerateContentConfigCommandHandlerDecorator( + c.Get>()) {Filename = filename}); - }); return this; } public NoCloudGeneratorBuilder ProxySettings(ConfigDriveProxySettings proxySettings) { - Container.RegisterDecorator, GenerateProxyConfigCommandHandlerDecorator>(); - Container.RegisterInitializer(h => - { - h.ProxySettings = proxySettings; - }); + Container.Decorate>( + c=> new GenerateProxyConfigCommandHandlerDecorator(c.Get>()){ProxySettings = proxySettings}); + return this; } diff --git a/src/CloudInit.ConfigDrive.NoCloud/NoCloud/NoCloudGeneratorBuilderExtensions.cs b/src/CloudInit.ConfigDrive.NoCloud/NoCloud/NoCloudGeneratorBuilderExtensions.cs index 89d3686..2f05013 100644 --- a/src/CloudInit.ConfigDrive.NoCloud/NoCloud/NoCloudGeneratorBuilderExtensions.cs +++ b/src/CloudInit.ConfigDrive.NoCloud/NoCloud/NoCloudGeneratorBuilderExtensions.cs @@ -4,7 +4,7 @@ namespace Contiva.CloudInit.ConfigDrive.NoCloud { public static class NoCloudGeneratorBuilderExtensions { - public static NoCloudGeneratorBuilder NoCloud(this GeneratorBuilder builder, NoCloudConfigDriveMetaData metaData) + public static NoCloudGeneratorBuilder NoCloud(this IGenerateableBuilder builder, NoCloudConfigDriveMetaData metaData) { return new NoCloudGeneratorBuilder(builder) { Metadata = metaData }; ; } diff --git a/src/CloudInit.ConfigDrive.WindowsImaging/CloudInit.ConfigDrive.WindowsImaging.csproj b/src/CloudInit.ConfigDrive.WindowsImaging/CloudInit.ConfigDrive.WindowsImaging.csproj index 213c34c..32c49eb 100644 --- a/src/CloudInit.ConfigDrive.WindowsImaging/CloudInit.ConfigDrive.WindowsImaging.csproj +++ b/src/CloudInit.ConfigDrive.WindowsImaging/CloudInit.ConfigDrive.WindowsImaging.csproj @@ -1,7 +1,7 @@  - net471 + net45 Contiva.CloudInit.ConfigDrive Contiva.CloudInit.ConfigDrive.WindowsImaging true diff --git a/src/CloudInit.ConfigDrive.WindowsImaging/Processing/WindowsImagingProcessorBuilder.cs b/src/CloudInit.ConfigDrive.WindowsImaging/Processing/WindowsImagingProcessorBuilder.cs index a928e72..c221e72 100644 --- a/src/CloudInit.ConfigDrive.WindowsImaging/Processing/WindowsImagingProcessorBuilder.cs +++ b/src/CloudInit.ConfigDrive.WindowsImaging/Processing/WindowsImagingProcessorBuilder.cs @@ -13,9 +13,8 @@ internal WindowsImagingProcessorBuilder(IBuilder innerBuilder) : base(innerBuild public ProcessorBuilder ImageFile(string filename) { Container - .RegisterDecorator, ImageFileProcessResultCommandHandlerDecoration>(); - Container.RegisterInitializer( - s => s.Filename = filename); + .Decorate>( + c=> new ImageFileProcessResultCommandHandlerDecoration(c.Get>()){Filename = filename}); return this; } diff --git a/src/CloudInit.ConfigDrive/CloudInit.ConfigDrive.csproj b/src/CloudInit.ConfigDrive/CloudInit.ConfigDrive.csproj index 08ead24..88429f4 100644 --- a/src/CloudInit.ConfigDrive/CloudInit.ConfigDrive.csproj +++ b/src/CloudInit.ConfigDrive/CloudInit.ConfigDrive.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net45;netstandard1.3;netstandard2.0 Contiva.CloudInit.ConfigDrive Contiva.CloudInit.ConfigDrive true @@ -19,11 +19,6 @@ - - - - - all diff --git a/src/CloudInit.ConfigDrive.Core/Generator/ConfigDriveGenerator.cs b/src/CloudInit.ConfigDrive/Generator/ConfigDriveGenerator.cs similarity index 100% rename from src/CloudInit.ConfigDrive.Core/Generator/ConfigDriveGenerator.cs rename to src/CloudInit.ConfigDrive/Generator/ConfigDriveGenerator.cs diff --git a/src/CloudInit.ConfigDrive/Generator/GeneratorBuilder.cs b/src/CloudInit.ConfigDrive/Generator/GeneratorBuilder.cs new file mode 100644 index 0000000..b59805c --- /dev/null +++ b/src/CloudInit.ConfigDrive/Generator/GeneratorBuilder.cs @@ -0,0 +1,39 @@ + +using Contiva.CloudInit.ConfigDrive.Injection; +using Contiva.CloudInit.ConfigDrive.Processing; + +namespace Contiva.CloudInit.ConfigDrive.Generator +{ + + public class GeneratorBuilder : GenerateableBuilder + { + + public static GeneratorBuilder Init() + { + var container = new Injectionist(); + container.Register( + c=> new ConfigDriveGenerator( + c.Get>(), + c.Get>())); + + return new GeneratorBuilder(container); + } + + protected GeneratorBuilder(Injectionist container) : base(container) + { + } + + protected GeneratorBuilder(BaseBuilder innerBuilder): base(innerBuilder) + { + } + + protected override void PrepareBuild() + { + if(!Container.Has>()) + Container.Register>( + c=> new DummyCommandHandler()); + + base.PrepareBuild(); + } + } +} diff --git a/src/CloudInit.ConfigDrive.Core/Processing/ProcessingBuilderExtensions.cs b/src/CloudInit.ConfigDrive/Processing/ProcessingBuilderExtensions.cs similarity index 100% rename from src/CloudInit.ConfigDrive.Core/Processing/ProcessingBuilderExtensions.cs rename to src/CloudInit.ConfigDrive/Processing/ProcessingBuilderExtensions.cs diff --git a/src/GenConfigDrive/Program.cs b/src/GenConfigDrive/Program.cs index 92d5578..a2282af 100644 --- a/src/GenConfigDrive/Program.cs +++ b/src/GenConfigDrive/Program.cs @@ -2,13 +2,12 @@ using System.IO; using System.Text; using CommandLine; -using Contiva.CloudInit.ConfigDrive; using Contiva.CloudInit.ConfigDrive.Generator; using Contiva.CloudInit.ConfigDrive.NoCloud; using Contiva.CloudInit.ConfigDrive.Processing; using Newtonsoft.Json.Linq; -namespace NewCloudInitConfigDrive +namespace Contiva.CloudInit.ConfigDrive { class Program { diff --git a/src/GenConfigDrive/Properties/launchSettings.json b/src/GenConfigDrive/Properties/launchSettings.json new file mode 100644 index 0000000..4e9d129 --- /dev/null +++ b/src/GenConfigDrive/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "GenConfigDrive": { + "commandName": "Project", + "commandLineArgs": "--hostname test" + } + } +} \ No newline at end of file diff --git a/src/Windows.ImagingApi/Windows.ImagingApi.csproj b/src/Windows.ImagingApi/Windows.ImagingApi.csproj index f48449f..843a9d4 100644 --- a/src/Windows.ImagingApi/Windows.ImagingApi.csproj +++ b/src/Windows.ImagingApi/Windows.ImagingApi.csproj @@ -8,7 +8,7 @@ false Contiva.Windows.ImagingApi Contiva.Windows.ImagingApi - v4.5.2 + v4.5