From 61b43d38f12f33b09dd8136c551ce66ee58df474 Mon Sep 17 00:00:00 2001 From: garrypas Date: Thu, 7 May 2015 00:32:54 +0100 Subject: [PATCH] Added Decorate() method to KernalBase --- src/Ninject/KernelBase.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Ninject/KernelBase.cs b/src/Ninject/KernelBase.cs index d4145974..de37e37b 100644 --- a/src/Ninject/KernelBase.cs +++ b/src/Ninject/KernelBase.cs @@ -599,5 +599,23 @@ public int Compare(IBinding x, IBinding y) return q.FirstOrDefault(); } } + + /// + /// Decorates one type with another + /// + /// The type to be decorated + /// The decorator that must inherit from the type it is decorating + /// The resulting binding + public IBindingWhenInNamedWithOrOnSyntax Decorate() + where WithThis : DecorateThis + { + var binding = GetBindings(typeof(DecorateThis)) + .Last(); + var lowerBinding = new BindingConfigurationBuilder(binding + .BindingConfiguration, binding.Metadata.Name, this); + var bindingSyntax = Bind(); + lowerBinding.WhenInjectedInto(); + return bindingSyntax.To(); + } } } \ No newline at end of file