diff --git a/README.md b/README.md index 446150e..85004fd 100644 --- a/README.md +++ b/README.md @@ -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 : IRepository where T : BaseEntity +{ + private readonly IRepository _innerRepository; + + public RepositoryLoggingDecorator(IRepository 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` or `IRepository`, the `RepositoryLoggingDecorator` will be applied. + ## License This project is licensed under the MIT license.