diff --git a/src/ModularPipelines/Context/IPipelineEncoding.cs b/src/ModularPipelines/Context/IPipelineEncoding.cs new file mode 100644 index 0000000000..9441b55b51 --- /dev/null +++ b/src/ModularPipelines/Context/IPipelineEncoding.cs @@ -0,0 +1,46 @@ +using ModularPipelines.Helpers; + +namespace ModularPipelines.Context; + +/// +/// Provides access to serialization and encoding helpers. +/// +/// +/// This interface groups JSON, XML, YAML serialization and encoding helpers (Hex, Base64, Hasher) +/// for better Interface Segregation. +/// +public interface IPipelineEncoding +{ + /// + /// Gets helpers for converting JSON. + /// + IJson Json { get; } + + /// + /// Gets helpers for convering XML. + /// + IXml Xml { get; } + + /// + /// Gets helpers for convering YAML. + /// + IYaml Yaml { get; } + + /// + /// Gets helpers for converting to and from hex strings. + /// + IHex Hex { get; } + + /// + /// Gets helpers for converting to and from Base64 strings. + /// + IBase64 Base64 { get; } + + /// + /// Gets helpers for hashing data. + /// + /// + /// Supports MD5, SHA1, SHA256, SHA512 hashing algorithms. + /// + IHasher Hasher { get; } +} diff --git a/src/ModularPipelines/Context/IPipelineEnvironment.cs b/src/ModularPipelines/Context/IPipelineEnvironment.cs new file mode 100644 index 0000000000..97f4194a03 --- /dev/null +++ b/src/ModularPipelines/Context/IPipelineEnvironment.cs @@ -0,0 +1,30 @@ +using ModularPipelines.Engine; +using ModularPipelines.Helpers; + +namespace ModularPipelines.Context; + +/// +/// Provides access to environment and build system detection. +/// +/// +/// This interface groups environment context and build system detection helpers +/// for better Interface Segregation. +/// +public interface IPipelineEnvironment +{ + /// + /// Gets helpers for getting information about the current environment. + /// + /// + /// Provides access to OS info, environment variables, working directory, etc. + /// + IEnvironmentContext Environment { get; } + + /// + /// Gets helpers for detecting the current build system. + /// + /// + /// Detects GitHub Actions, Azure DevOps, Jenkins, GitLab CI, etc. + /// + IBuildSystemDetector BuildSystemDetector { get; } +} diff --git a/src/ModularPipelines/Context/IPipelineFileSystem.cs b/src/ModularPipelines/Context/IPipelineFileSystem.cs new file mode 100644 index 0000000000..6e29e171b4 --- /dev/null +++ b/src/ModularPipelines/Context/IPipelineFileSystem.cs @@ -0,0 +1,31 @@ +using ModularPipelines.Helpers; + +namespace ModularPipelines.Context; + +/// +/// Provides access to file system operations. +/// +/// +/// This interface groups file system, zip, and checksum helpers +/// for better Interface Segregation. +/// +public interface IPipelineFileSystem +{ + /// + /// Gets helpers for interacting with the filesystem. + /// + /// + /// Provides file/directory operations with logging and error handling. + /// + IFileSystemContext FileSystem { get; } + + /// + /// Gets helpers for zipping and unzipping files and directories. + /// + IZip Zip { get; } + + /// + /// Gets helpers for checking the Checksum of a file. + /// + IChecksum Checksum { get; } +} diff --git a/src/ModularPipelines/Context/IPipelineHookContext.cs b/src/ModularPipelines/Context/IPipelineHookContext.cs index 8665e05320..c99ce7f4b4 100644 --- a/src/ModularPipelines/Context/IPipelineHookContext.cs +++ b/src/ModularPipelines/Context/IPipelineHookContext.cs @@ -23,199 +23,19 @@ namespace ModularPipelines.Context; /// Extension Pattern: /// Tool integrations (ModularPipelines.Git, ModularPipelines.Docker, etc.) add extension methods /// like context.Git() and context.Docker() that provide strongly-typed APIs for those tools. +/// +/// Interface Segregation: +/// This interface inherits from focused sub-interfaces (IPipelineServices, IPipelineLogging, etc.) +/// allowing consumers to depend on only the subset of functionality they need. /// -public interface IPipelineHookContext +public interface IPipelineHookContext : + IPipelineServices, + IPipelineLogging, + IPipelineTools, + IPipelineEncoding, + IPipelineFileSystem, + IPipelineEnvironment { - #region DependencyInjection - - /// - /// Gets the service provider orchestrating DI within the pipeline. - /// - /// - /// Use the generic Get<T>() method instead of accessing ServiceProvider directly - /// when possible for better type safety. - /// - public IServiceProvider ServiceProvider { get; } - - /// - /// Helper method for retrieving services from the Service Provider. - /// - /// Type to retrieve. - /// The service instance, or null if not registered. - public T? Get(); - - #endregion - - #region Configuration - - /// - /// Gets the configuration powering the pipeline. - /// - /// - /// Configuration is loaded from appsettings.json, environment variables, user secrets, and command line. - /// - public IConfiguration Configuration { get; } - - /// - /// Gets the pipeline's options. - /// - public IOptions PipelineOptions { get; } - - #endregion - - #region Logging - - /// - /// Gets the logger to be used from the pipeline. - /// - /// - /// This logger is module-scoped and will include the module name in log output. - /// - public IModuleLogger Logger { get; } - - #endregion - - #region EnvironmentHelpers - - /// - /// Gets helpers for getting information about the current environment. - /// - /// - /// Provides access to OS info, environment variables, working directory, etc. - /// - public IEnvironmentContext Environment { get; } - - /// - /// Gets helpers for detecting the current build system. - /// - /// - /// Detects GitHub Actions, Azure DevOps, Jenkins, GitLab CI, etc. - /// - public IBuildSystemDetector BuildSystemDetector { get; } - - #endregion - - #region FileSystemHelpers - - /// - /// Gets helpers for interacting with the filesystem. - /// - /// - /// Provides file/directory operations with logging and error handling. - /// - public IFileSystemContext FileSystem { get; } - - /// - /// Gets helpers for zipping and unzipping files and directories. - /// - public IZip Zip { get; } - - /// - /// Gets helpers for checking the Checksum of a file. - /// - IChecksum Checksum { get; } - - #endregion - - #region CommandExecution - - /// - /// Gets helpers for running commands. - /// - /// - /// Provides cross-platform command execution with output capture and logging. - /// - public ICommand Command { get; } - - /// - /// Gets helpers for running powershell. - /// - public IPowershell Powershell { get; } - - /// - /// Gets helpers for executing bash commands. - /// - public IBash Bash { get; } - - #endregion - - #region Serialization - - /// - /// Gets helpers for converting JSON. - /// - public IJson Json { get; } - - /// - /// Gets helpers for convering XML. - /// - public IXml Xml { get; } - - /// - /// Gets helpers for convering YAML. - /// - public IYaml Yaml { get; } - - #endregion - - #region Encoding - - /// - /// Gets helpers for converting to and from hex strings. - /// - public IHex Hex { get; } - - /// - /// Gets helpers for converting to and from Base64 strings. - /// - public IBase64 Base64 { get; } - - #endregion - - #region Security - - /// - /// Gets helpers for hashing data. - /// - /// - /// Supports MD5, SHA1, SHA256, SHA512 hashing algorithms. - /// - public IHasher Hasher { get; } - - #endregion - - #region NetworkHelpers - - /// - /// Gets helpers for sending HTTP requests. - /// - /// - /// Provides a configured HttpClient with retry policies and logging. - /// - public IHttp Http { get; } - - /// - /// Gets helpers for downloading data from the web. - /// - /// - /// Includes progress tracking and verification helpers. - /// - public IDownloader Downloader { get; } - - #endregion - - #region Installation - - /// - /// Gets helpers for installing applications. - /// - /// - /// Supports package managers like Chocolatey, apt, brew, etc. - /// - public IInstaller Installer { get; } - - #endregion - #region Internal /// @@ -240,4 +60,4 @@ public interface IPipelineHookContext internal EngineCancellationToken EngineCancellationToken { get; } #endregion -} \ No newline at end of file +} diff --git a/src/ModularPipelines/Context/IPipelineLogging.cs b/src/ModularPipelines/Context/IPipelineLogging.cs new file mode 100644 index 0000000000..883cf64f2d --- /dev/null +++ b/src/ModularPipelines/Context/IPipelineLogging.cs @@ -0,0 +1,20 @@ +using ModularPipelines.Logging; + +namespace ModularPipelines.Context; + +/// +/// Provides access to logging functionality. +/// +/// +/// This interface groups logging-related members for better Interface Segregation. +/// +public interface IPipelineLogging +{ + /// + /// Gets the logger to be used from the pipeline. + /// + /// + /// This logger is module-scoped and will include the module name in log output. + /// + IModuleLogger Logger { get; } +} diff --git a/src/ModularPipelines/Context/IPipelineServices.cs b/src/ModularPipelines/Context/IPipelineServices.cs new file mode 100644 index 0000000000..5fd70978c8 --- /dev/null +++ b/src/ModularPipelines/Context/IPipelineServices.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using ModularPipelines.Options; + +namespace ModularPipelines.Context; + +/// +/// Provides access to dependency injection and configuration services. +/// +/// +/// This interface groups DI and configuration-related members for better Interface Segregation. +/// +public interface IPipelineServices +{ + /// + /// Gets the service provider orchestrating DI within the pipeline. + /// + /// + /// Use the generic Get<T>() method instead of accessing ServiceProvider directly + /// when possible for better type safety. + /// + IServiceProvider ServiceProvider { get; } + + /// + /// Helper method for retrieving services from the Service Provider. + /// + /// Type to retrieve. + /// The service instance, or null if not registered. + T? Get(); + + /// + /// Gets the configuration powering the pipeline. + /// + /// + /// Configuration is loaded from appsettings.json, environment variables, user secrets, and command line. + /// + IConfiguration Configuration { get; } + + /// + /// Gets the pipeline's options. + /// + IOptions PipelineOptions { get; } +} diff --git a/src/ModularPipelines/Context/IPipelineTools.cs b/src/ModularPipelines/Context/IPipelineTools.cs new file mode 100644 index 0000000000..697f02a0f8 --- /dev/null +++ b/src/ModularPipelines/Context/IPipelineTools.cs @@ -0,0 +1,56 @@ +using ModularPipelines.Helpers; +using ModularPipelines.Http; + +namespace ModularPipelines.Context; + +/// +/// Provides access to command execution and tool helpers. +/// +/// +/// This interface groups command execution, HTTP, download, and installation helpers +/// for better Interface Segregation. +/// +public interface IPipelineTools +{ + /// + /// Gets helpers for running commands. + /// + /// + /// Provides cross-platform command execution with output capture and logging. + /// + ICommand Command { get; } + + /// + /// Gets helpers for running powershell. + /// + IPowershell Powershell { get; } + + /// + /// Gets helpers for executing bash commands. + /// + IBash Bash { get; } + + /// + /// Gets helpers for sending HTTP requests. + /// + /// + /// Provides a configured HttpClient with retry policies and logging. + /// + IHttp Http { get; } + + /// + /// Gets helpers for downloading data from the web. + /// + /// + /// Includes progress tracking and verification helpers. + /// + IDownloader Downloader { get; } + + /// + /// Gets helpers for installing applications. + /// + /// + /// Supports package managers like Chocolatey, apt, brew, etc. + /// + IInstaller Installer { get; } +}