Skip to content

Commit

Permalink
Change README for DI
Browse files Browse the repository at this point in the history
  • Loading branch information
NotCoffee418 committed Mar 23, 2024
1 parent a954f14 commit a246fee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CSharpScriptOperations/OperationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static async Task StartListeningAsync(IServiceProvider serviceProvider =
?? Services.BuildServiceProvider();

// List all operations
Console.Write(OperationManager.GetOperationsDisplay());
Console.Write(GetOperationsDisplay());

// Request user
while (true) // Breakout is calling Exit operation
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,32 @@ OperationManager.RegisterOperation(typeof(HelloWorld));
```

### 4. Register dependencies (optional)
If you'd like to use dependency injection with autofac, make sure to install the [autofac nuget package](https://www.nuget.org/packages/Autofac) and add the using statement.
You can optionally use dependency injection with Autofac or Microsoft Dependency Injection.


```csharp
using Autofac;
```
Register any dependencies to `OperationManager.ContainerBuilder` before starting the listener.
```csharp
ContainerBuilder AutofacContainerBuilder = new ContainerBuilder();

// Include application dependencies
OperationManager.ContainerBuilder
.RegisterType<ExampleDependency>()
.As<IExampleDependency>();

// Include the services registered by the OperationManager
AutofacContainerBuilder.Populate(OperationManager.Services);

// Build the container
var serviceProvider = new AutofacServiceProvider(AutofacContainerBuilder.Build());
```

### 5. Start the listener
This will display our options and interpret user input to run the approperiate operation.
```csharp
await OperationManager.StartListeningAsync();

// or if you use dependency injection
await OperationManager.StartListeningAsync(serviceProvider);
```
Alternatively you can implement your own version of `StartListening()`.
You can access the registered operations and it's classes through the
Expand Down

0 comments on commit a246fee

Please sign in to comment.