Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Maes committed Oct 11, 2024
1 parent 1fe0b15 commit 8305e47
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,32 @@ public class LoggingDecorator : IMyService
}
```

### Decorators with generics:

You can also create decorators for generic services.

```csharp
[RegisterDecorator(typeof(IRepository<>))]
public class RepositoryLoggingDecorator<T> : IRepository<T> where T : BaseEntity
{
private readonly IRepository<T> _innerRepository;

public RepositoryLoggingDecorator(IRepository<T> innerRepository)
{
_innerRepository = innerRepository;
}

public void Add(T entity)
{
Console.WriteLine($"Adding entity of type {typeof(T).Name}");
_innerRepository.Add(entity);
Console.WriteLine($"Added entity of type {typeof(T).Name}");
}
}
```

Now, when you resolve `IRepository<Customer>` or `IRepository<Product>`, the `RepositoryLoggingDecorator<T>` will be applied.

## License

This project is licensed under the MIT license.

0 comments on commit 8305e47

Please sign in to comment.