Skip to content

Commit f01ebb4

Browse files
thomhurstclaude
andauthored
refactor: Split IPipelineHookContext for Interface Segregation Principle compliance (#1463)
* chore: Add .worktrees/ to .gitignore for parallel development 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: Split IPipelineHookContext into focused interfaces for ISP compliance Split the monolithic IPipelineHookContext (27+ members) into focused sub-interfaces to comply with the Interface Segregation Principle (ISP): - IPipelineServices: DI and configuration (ServiceProvider, Get<T>, Configuration, PipelineOptions) - IPipelineLogging: Logging functionality (Logger) - IPipelineTools: Command execution and tools (Command, Powershell, Bash, Http, Downloader, Installer) - IPipelineEncoding: Serialization and encoding (Json, Xml, Yaml, Hex, Base64, Hasher) - IPipelineFileSystem: File operations (FileSystem, Zip, Checksum) - IPipelineEnvironment: Environment and build detection (Environment, BuildSystemDetector) IPipelineHookContext now inherits from all sub-interfaces, maintaining full backwards compatibility while allowing consumers to depend on only the subset of functionality they need. Fixes #1454 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1960bd4 commit f01ebb4

7 files changed

Lines changed: 238 additions & 192 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using ModularPipelines.Helpers;
2+
3+
namespace ModularPipelines.Context;
4+
5+
/// <summary>
6+
/// Provides access to serialization and encoding helpers.
7+
/// </summary>
8+
/// <remarks>
9+
/// This interface groups JSON, XML, YAML serialization and encoding helpers (Hex, Base64, Hasher)
10+
/// for better Interface Segregation.
11+
/// </remarks>
12+
public interface IPipelineEncoding
13+
{
14+
/// <summary>
15+
/// Gets helpers for converting JSON.
16+
/// </summary>
17+
IJson Json { get; }
18+
19+
/// <summary>
20+
/// Gets helpers for convering XML.
21+
/// </summary>
22+
IXml Xml { get; }
23+
24+
/// <summary>
25+
/// Gets helpers for convering YAML.
26+
/// </summary>
27+
IYaml Yaml { get; }
28+
29+
/// <summary>
30+
/// Gets helpers for converting to and from hex strings.
31+
/// </summary>
32+
IHex Hex { get; }
33+
34+
/// <summary>
35+
/// Gets helpers for converting to and from Base64 strings.
36+
/// </summary>
37+
IBase64 Base64 { get; }
38+
39+
/// <summary>
40+
/// Gets helpers for hashing data.
41+
/// </summary>
42+
/// <remarks>
43+
/// Supports MD5, SHA1, SHA256, SHA512 hashing algorithms.
44+
/// </remarks>
45+
IHasher Hasher { get; }
46+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using ModularPipelines.Engine;
2+
using ModularPipelines.Helpers;
3+
4+
namespace ModularPipelines.Context;
5+
6+
/// <summary>
7+
/// Provides access to environment and build system detection.
8+
/// </summary>
9+
/// <remarks>
10+
/// This interface groups environment context and build system detection helpers
11+
/// for better Interface Segregation.
12+
/// </remarks>
13+
public interface IPipelineEnvironment
14+
{
15+
/// <summary>
16+
/// Gets helpers for getting information about the current environment.
17+
/// </summary>
18+
/// <remarks>
19+
/// Provides access to OS info, environment variables, working directory, etc.
20+
/// </remarks>
21+
IEnvironmentContext Environment { get; }
22+
23+
/// <summary>
24+
/// Gets helpers for detecting the current build system.
25+
/// </summary>
26+
/// <remarks>
27+
/// Detects GitHub Actions, Azure DevOps, Jenkins, GitLab CI, etc.
28+
/// </remarks>
29+
IBuildSystemDetector BuildSystemDetector { get; }
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using ModularPipelines.Helpers;
2+
3+
namespace ModularPipelines.Context;
4+
5+
/// <summary>
6+
/// Provides access to file system operations.
7+
/// </summary>
8+
/// <remarks>
9+
/// This interface groups file system, zip, and checksum helpers
10+
/// for better Interface Segregation.
11+
/// </remarks>
12+
public interface IPipelineFileSystem
13+
{
14+
/// <summary>
15+
/// Gets helpers for interacting with the filesystem.
16+
/// </summary>
17+
/// <remarks>
18+
/// Provides file/directory operations with logging and error handling.
19+
/// </remarks>
20+
IFileSystemContext FileSystem { get; }
21+
22+
/// <summary>
23+
/// Gets helpers for zipping and unzipping files and directories.
24+
/// </summary>
25+
IZip Zip { get; }
26+
27+
/// <summary>
28+
/// Gets helpers for checking the Checksum of a file.
29+
/// </summary>
30+
IChecksum Checksum { get; }
31+
}

src/ModularPipelines/Context/IPipelineHookContext.cs

Lines changed: 12 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -23,199 +23,19 @@ namespace ModularPipelines.Context;
2323
/// Extension Pattern:
2424
/// Tool integrations (ModularPipelines.Git, ModularPipelines.Docker, etc.) add extension methods
2525
/// like context.Git() and context.Docker() that provide strongly-typed APIs for those tools.
26+
///
27+
/// Interface Segregation:
28+
/// This interface inherits from focused sub-interfaces (IPipelineServices, IPipelineLogging, etc.)
29+
/// allowing consumers to depend on only the subset of functionality they need.
2630
/// </remarks>
27-
public interface IPipelineHookContext
31+
public interface IPipelineHookContext :
32+
IPipelineServices,
33+
IPipelineLogging,
34+
IPipelineTools,
35+
IPipelineEncoding,
36+
IPipelineFileSystem,
37+
IPipelineEnvironment
2838
{
29-
#region DependencyInjection
30-
31-
/// <summary>
32-
/// Gets the service provider orchestrating DI within the pipeline.
33-
/// </summary>
34-
/// <remarks>
35-
/// Use the generic Get&lt;T&gt;() method instead of accessing ServiceProvider directly
36-
/// when possible for better type safety.
37-
/// </remarks>
38-
public IServiceProvider ServiceProvider { get; }
39-
40-
/// <summary>
41-
/// Helper method for retrieving services from the Service Provider.
42-
/// </summary>
43-
/// <typeparam name="T">Type to retrieve.</typeparam>
44-
/// <returns>The service instance, or null if not registered.</returns>
45-
public T? Get<T>();
46-
47-
#endregion
48-
49-
#region Configuration
50-
51-
/// <summary>
52-
/// Gets the configuration powering the pipeline.
53-
/// </summary>
54-
/// <remarks>
55-
/// Configuration is loaded from appsettings.json, environment variables, user secrets, and command line.
56-
/// </remarks>
57-
public IConfiguration Configuration { get; }
58-
59-
/// <summary>
60-
/// Gets the pipeline's options.
61-
/// </summary>
62-
public IOptions<PipelineOptions> PipelineOptions { get; }
63-
64-
#endregion
65-
66-
#region Logging
67-
68-
/// <summary>
69-
/// Gets the logger to be used from the pipeline.
70-
/// </summary>
71-
/// <remarks>
72-
/// This logger is module-scoped and will include the module name in log output.
73-
/// </remarks>
74-
public IModuleLogger Logger { get; }
75-
76-
#endregion
77-
78-
#region EnvironmentHelpers
79-
80-
/// <summary>
81-
/// Gets helpers for getting information about the current environment.
82-
/// </summary>
83-
/// <remarks>
84-
/// Provides access to OS info, environment variables, working directory, etc.
85-
/// </remarks>
86-
public IEnvironmentContext Environment { get; }
87-
88-
/// <summary>
89-
/// Gets helpers for detecting the current build system.
90-
/// </summary>
91-
/// <remarks>
92-
/// Detects GitHub Actions, Azure DevOps, Jenkins, GitLab CI, etc.
93-
/// </remarks>
94-
public IBuildSystemDetector BuildSystemDetector { get; }
95-
96-
#endregion
97-
98-
#region FileSystemHelpers
99-
100-
/// <summary>
101-
/// Gets helpers for interacting with the filesystem.
102-
/// </summary>
103-
/// <remarks>
104-
/// Provides file/directory operations with logging and error handling.
105-
/// </remarks>
106-
public IFileSystemContext FileSystem { get; }
107-
108-
/// <summary>
109-
/// Gets helpers for zipping and unzipping files and directories.
110-
/// </summary>
111-
public IZip Zip { get; }
112-
113-
/// <summary>
114-
/// Gets helpers for checking the Checksum of a file.
115-
/// </summary>
116-
IChecksum Checksum { get; }
117-
118-
#endregion
119-
120-
#region CommandExecution
121-
122-
/// <summary>
123-
/// Gets helpers for running commands.
124-
/// </summary>
125-
/// <remarks>
126-
/// Provides cross-platform command execution with output capture and logging.
127-
/// </remarks>
128-
public ICommand Command { get; }
129-
130-
/// <summary>
131-
/// Gets helpers for running powershell.
132-
/// </summary>
133-
public IPowershell Powershell { get; }
134-
135-
/// <summary>
136-
/// Gets helpers for executing bash commands.
137-
/// </summary>
138-
public IBash Bash { get; }
139-
140-
#endregion
141-
142-
#region Serialization
143-
144-
/// <summary>
145-
/// Gets helpers for converting JSON.
146-
/// </summary>
147-
public IJson Json { get; }
148-
149-
/// <summary>
150-
/// Gets helpers for convering XML.
151-
/// </summary>
152-
public IXml Xml { get; }
153-
154-
/// <summary>
155-
/// Gets helpers for convering YAML.
156-
/// </summary>
157-
public IYaml Yaml { get; }
158-
159-
#endregion
160-
161-
#region Encoding
162-
163-
/// <summary>
164-
/// Gets helpers for converting to and from hex strings.
165-
/// </summary>
166-
public IHex Hex { get; }
167-
168-
/// <summary>
169-
/// Gets helpers for converting to and from Base64 strings.
170-
/// </summary>
171-
public IBase64 Base64 { get; }
172-
173-
#endregion
174-
175-
#region Security
176-
177-
/// <summary>
178-
/// Gets helpers for hashing data.
179-
/// </summary>
180-
/// <remarks>
181-
/// Supports MD5, SHA1, SHA256, SHA512 hashing algorithms.
182-
/// </remarks>
183-
public IHasher Hasher { get; }
184-
185-
#endregion
186-
187-
#region NetworkHelpers
188-
189-
/// <summary>
190-
/// Gets helpers for sending HTTP requests.
191-
/// </summary>
192-
/// <remarks>
193-
/// Provides a configured HttpClient with retry policies and logging.
194-
/// </remarks>
195-
public IHttp Http { get; }
196-
197-
/// <summary>
198-
/// Gets helpers for downloading data from the web.
199-
/// </summary>
200-
/// <remarks>
201-
/// Includes progress tracking and verification helpers.
202-
/// </remarks>
203-
public IDownloader Downloader { get; }
204-
205-
#endregion
206-
207-
#region Installation
208-
209-
/// <summary>
210-
/// Gets helpers for installing applications.
211-
/// </summary>
212-
/// <remarks>
213-
/// Supports package managers like Chocolatey, apt, brew, etc.
214-
/// </remarks>
215-
public IInstaller Installer { get; }
216-
217-
#endregion
218-
21939
#region Internal
22040

22141
/// <summary>
@@ -240,4 +60,4 @@ public interface IPipelineHookContext
24060
internal EngineCancellationToken EngineCancellationToken { get; }
24161

24262
#endregion
243-
}
63+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using ModularPipelines.Logging;
2+
3+
namespace ModularPipelines.Context;
4+
5+
/// <summary>
6+
/// Provides access to logging functionality.
7+
/// </summary>
8+
/// <remarks>
9+
/// This interface groups logging-related members for better Interface Segregation.
10+
/// </remarks>
11+
public interface IPipelineLogging
12+
{
13+
/// <summary>
14+
/// Gets the logger to be used from the pipeline.
15+
/// </summary>
16+
/// <remarks>
17+
/// This logger is module-scoped and will include the module name in log output.
18+
/// </remarks>
19+
IModuleLogger Logger { get; }
20+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Microsoft.Extensions.Options;
3+
using ModularPipelines.Options;
4+
5+
namespace ModularPipelines.Context;
6+
7+
/// <summary>
8+
/// Provides access to dependency injection and configuration services.
9+
/// </summary>
10+
/// <remarks>
11+
/// This interface groups DI and configuration-related members for better Interface Segregation.
12+
/// </remarks>
13+
public interface IPipelineServices
14+
{
15+
/// <summary>
16+
/// Gets the service provider orchestrating DI within the pipeline.
17+
/// </summary>
18+
/// <remarks>
19+
/// Use the generic Get&lt;T&gt;() method instead of accessing ServiceProvider directly
20+
/// when possible for better type safety.
21+
/// </remarks>
22+
IServiceProvider ServiceProvider { get; }
23+
24+
/// <summary>
25+
/// Helper method for retrieving services from the Service Provider.
26+
/// </summary>
27+
/// <typeparam name="T">Type to retrieve.</typeparam>
28+
/// <returns>The service instance, or null if not registered.</returns>
29+
T? Get<T>();
30+
31+
/// <summary>
32+
/// Gets the configuration powering the pipeline.
33+
/// </summary>
34+
/// <remarks>
35+
/// Configuration is loaded from appsettings.json, environment variables, user secrets, and command line.
36+
/// </remarks>
37+
IConfiguration Configuration { get; }
38+
39+
/// <summary>
40+
/// Gets the pipeline's options.
41+
/// </summary>
42+
IOptions<PipelineOptions> PipelineOptions { get; }
43+
}

0 commit comments

Comments
 (0)