Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson-at-westermo authored Mar 8, 2024
1 parent ec9d124 commit 22a55a2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,23 @@ public DependencyInjectionContainer(CommandLineOptions options)
}
```
And will thus require the user to provide the value at container-creation time.

### Injecting Methods
FactoryGenerator is not limited to only allowing for the injection of classes. Consider the following:
```csharp
using FactoryGenerator.Attributes;

namespace Somewhere;
public interface IResultType;
public interface IProvider
{
[Inject, Singleton]
IResultType Method();
}
[Inject]
public class Provider : IProvider
{
public IResultType Method() => /*Implementation Code*/
}
```
With this code, it is now possible to do `container.Resolve<IResultType>()`, which will effectively return the result of `new Provider().Method()`, although, since `Method` is `[Inject]`ed as a `[Singleton]`, the result will be cached and the same instance will be returned at every call to `Resolve` as well as shared between all Injected implementations that require a `IResultType`.

0 comments on commit 22a55a2

Please sign in to comment.