AutomationIoC.PSCmdlets
2.1.0-alpha2
dotnet add package AutomationIoC.PSCmdlets --version 2.1.0-alpha2
NuGet\Install-Package AutomationIoC.PSCmdlets -Version 2.1.0-alpha2
<PackageReference Include="AutomationIoC.PSCmdlets" Version="2.1.0-alpha2" />
paket add AutomationIoC.PSCmdlets --version 2.1.0-alpha2
#r "nuget: AutomationIoC.PSCmdlets, 2.1.0-alpha2"
// Install AutomationIoC.PSCmdlets as a Cake Addin #addin nuget:?package=AutomationIoC.PSCmdlets&version=2.1.0-alpha2&prerelease // Install AutomationIoC.PSCmdlets as a Cake Tool #tool nuget:?package=AutomationIoC.PSCmdlets&version=2.1.0-alpha2&prerelease
AutomationIoC.PSCmdlets
Dependency Injection Framework for C# PowerShell Cmdlets
Requirements
- .NET 7 or .NET 6
- PowerShell 7.3 or greater
Getting Started
Installation
dotnet add package AutomationIoC.PSCmdlets
Development
See Sample Projects for a full sample solution
Add the following to your .csproj file
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Add a Startup class
public class Startup : IoCStartup
{
// Add any configuration sources or data needed
public override void Configure(IConfigurationBuilder configurationBuilder)
{
// AutomationEnvironment class allows retrieving global PowerShell
// variables during service configuration.
var environment =
AutomationEnvironment.GetVariable<string>("AppEnvironment");
var appSettings = new Dictionary<string, string>()
{
["TestOptionsConfig:TestProperty"] = "This is an example",
["AppEnvironment"] = environment
};
configurationBuilder.AddInMemoryCollection(appSettings);
}
// Configure services/lifetimes
public override void ConfigureServices(IServiceCollection services)
{
services.Configure<TestOptions>(Configuration.GetSection("TestOptionsConfig"));
services.AddTransient<ITestDependencyOne, TestDependencyOne>();
services.AddTransient<ITestDependencyTwo, TestDependencyTwo>();
// ...
// other services, client, etc.
}
}
Add a PowerShell Command with Dependencies Injected
Synchronous process example
[Cmdlet(VerbsLifecycle.Submit, "Data")]
public class SubmitData : IoCShell<Startup>
{
[Parameter(Mandatory = true)]
public string Id { get; set; }
[AutomationDependency]
protected ITestDependencyOne TestDependencyOne { get; set; }
[AutomationDependency]
protected ITestDependencyTwo testDependencyTwo { get; set; }
[AutomationDependency]
private ILogger<RequestCard> logger { get; set; }
protected override void ProcessRecord()
{
base.ProcessRecord();
TestDependencyOne.PushTestId(Id);
TestData testData = testDependencyTwo.GetTestData(Id);
logger.LogInformation("Auto Generated Data: {Id} - {Name}", Id, testData.Name);
WriteObject(testData);
}
}
Asynchronous process example
[Cmdlet(VerbsLifecycle.Submit, "DataAsync")]
public class SubmitDataAsync : IoCShellAsync<Startup>
{
[Parameter(Mandatory = true)]
public string Id { get; set; }
[AutomationDependency]
protected ITestDependencyOne TestDependencyOne { get; set; }
[AutomationDependency]
protected ITestDependencyTwo testDependencyTwo { get; set; }
[AutomationDependency]
private ILogger<RequestCard> logger { get; set; }
protected override async Task ProcessRecordAsync()
{
await TestDependencyOne.PushTestIdAsync(Id);
TestData testData = await testDependencyTwo.GetTestDataAsync(Id);
logger.LogInformation("Auto Generated Data: {Id} - {Name}", Id, testData.Name);
WriteObject(testData);
}
}
Execution
In PowerShell terminal run the following:
Import-Module <path-to-your-dll>/<your-assembly>.dll -V
You should see your custom commands listed in the verbose output (signaled by -v
).
Now you are ready to run your own custom commands!
The following example is based on command name from above:
Submit-Data -id "ThisIsATestId"
See Project - launch.json for a sample on launching your module through VS Code
Resources
Related Packages
Package | Description |
---|---|
AutomationIoC.PSCmdlets.Tools | Tooling for running/testing C# PowerShell Cmdlets |
AutomationIoC | Framework Runtime for AutomationIoC Console Applications and PowerShell Cmdlets |
AutomationIoC.Consoles | Dependency Injection Framework for C# Console Applications |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- AutomationIoC (>= 2.1.0-alpha2)
- PowerShellStandard.Library (>= 5.1.1)
-
net7.0
- AutomationIoC (>= 2.1.0-alpha2)
- PowerShellStandard.Library (>= 5.1.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AutomationIoC.PSCmdlets:
Package | Downloads |
---|---|
AutomationIoC.PSCmdlets.Tools
Development tools for running/testing Cmdlets built with AutomationIoC framework |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
2.1.0-alpha2 | 133 | 8/12/2023 | |
2.1.0-alpha1 | 84 | 6/16/2023 | |
2.0.0-preview1 | 78 | 6/16/2023 | |
2.0.0-alpha1 | 86 | 6/10/2023 |