-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResolveMany if singleton decorators decorates the first item only #254
Comments
Apparently https://dotnetfiddle.net/E0b9WO using System;
using System.Linq;
using DryIoc;
public class Program
{
public static void Main()
{
var c = new Container();
c.Register<I, A>(Reuse.Singleton);
c.Register<I, B>(Reuse.Singleton);
// works in 4.1.3 but doesn't in 4.1.4
c.RegisterDelegate<I, I>(i => new D(i), setup: Setup.Decorator);
// does not work
//c.RegisterDelegateDecorator<I>(_ => i => new D(i));
var ii = c.ResolveMany<I>().ToArray();
Console.WriteLine(ii[0].GetType() + ", " + ii[1].GetType());
Console.WriteLine(((D)ii[0]).Inner.GetType() + ", " + ((D)ii[1]).Inner.GetType());
}
interface I {}
class A : I {}
class B : I {}
class D : I
{
public D(I i) { Inner = i; }
public I Inner { get; set; }
}
} |
It also seems like 4.1.3 does not work either in case that the delegate is registered as Singleton as well: So if you want the Decorator service to be a Singelton as well as the Decorated service, there no apparent way around that. https://dotnetfiddle.net/ZcBKn5 using System;
using System.Linq;
using DryIoc;
public class Program
{
public static void Main()
{
var c = new Container();
c.Register<I, A>(Reuse.Singleton);
c.Register<I, B>(Reuse.Singleton);
c.RegisterDelegate<I, I>(i => new D(i), Reuse.Singleton, setup: Setup.Decorator);
var ii = c.ResolveMany<I>().ToArray();
Console.WriteLine(ii[0].GetType() + ", " + ii[1].GetType());
Console.WriteLine(((D)ii[0]).Inner.GetType() + ", " + ((D)ii[1]).Inner.GetType());
var jj = c.ResolveMany<I>().ToArray();
Console.WriteLine("Same: " + object.ReferenceEquals(ii[0], jj[0]));
}
interface I {}
class A : I {}
class B : I {}
class D : I
{
public D(I i) { Inner = i; }
public I Inner { get; set; }
}
} |
@hennys It is funny how this bug is so diverse and persistent. Thanks for the reporting. I will look. |
added UpdateItemOrShrinkUnsafe and updated Copy to use Array.Copy optimize decorator sorting for 2 items
* added test for #254 * ignoring the failed test * Cherry pick commit 'c7f698c' * Cherry pick commit '285214f' * Cherry pick commit '7dec0b9' * Cherry pick commit '0a2091a' * Cherry pick commit '517c44f' * Cherry pick commit '5d07bc6' * Cherry pick commit '41eb818' * #254 - make the obsoletion of RegisterDelegateDecorator in the next major version more obvious * added: simplest case FactoryMethod constructor and updated the usages * simplifying ParameterServiceInfo.Of * removing the code doing nothing * added: test with singleton decorator for #254 added UpdateItemOrShrinkUnsafe and updated Copy to use Array.Copy optimize decorator sorting for 2 items * revert back to the Match because using UpdateItemOrShrinkUnsafe is pointless * #254 reimplement RegisterDelegateDecorator in terms of RegisterDelegate * cleanup unused things * dead code cleanup * sharing the RequestStack for the Validate * optimizing out double GetParameters when parameters are already resolved by ConstructorWithResolvableArguments added the missing validation check for the property injection #242 * enable back ignored NCrunch test including ReducedStackoverflow * small cleanup * added sorting benchmark and implemented decorator sorting for more than 2 * small comments cleanup * -2kb by removing unnecassery creation of FactoryMethod * fixed: #254 * improving the error messages * release notes for the v4.1.4 * updated benchmarks
https://dotnetfiddle.net/E0b9WO
This should work.
The text was updated successfully, but these errors were encountered: