Locate ignores extraData
See original GitHub issueGrace 7.1.0.0 VS2019 16.3.10 Target .NET Framework 4.6.2
Locate method ignores extraData parameter, creates new instance for constructor parameter value instead of passing extraData value.
Sample:
using System;
using Grace.DependencyInjection;
namespace Grace.Err1
{
class A
{
public readonly B b;
public A(B b)
{
this.b = b;
}
}
class B
{
public string c = "Default";
public B()
{
}
}
class Program
{
static void Main(string[] args)
{
var container = new DependencyInjectionContainer();
container.Configure(registry =>
{
registry.Export<A>();
});
var a2 = container.Locate<A>(new { b = new B { c = "New C" } });
Console.WriteLine($"{a2.b.c}");
}
}
}
Expected output:
New C
Actual output:
Default
Workaround - disable auto registering types:
var container = new DependencyInjectionContainer(config =>
{
config.AutoRegisterUnknown = false;
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Passing instance type in ExtraData is ignored · Issue #273
When I pass a class, the locate method ignores it and just creates the object again. I'm trying to pass custom instances of...
Read more >Send EXTRA data via PendingIntent problem
I found that if the Intent that was used to create the Pending intent has any extras already in it then the new...
Read more >EZZ9718I extra data in root hints ' file_name '
The extra data will be ignored. Operator response. Examine the root hints file, file_name and remove all resource records except the NS and...
Read more >Failure to download extra data files
Hello! I am using UBUNTU 16.04...have had no issues, but recently I get the error message in a pop-up box indicated in the...
Read more >awk - completely ignore lines that start with a specific pattern
I have a script which analyzes the output of a computation software. sometimes the output comes with some extra data that are irrelevant...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think you’re misunderstanding something because Grace does support passing parameters to constructors through extra data. If you disable auto registration for the type you want to pass it will use it out of extra data.
@Forester- if the issue ultimately is that you can’t pass in a model through extra data I think it’s reasonable just to black list the namespace your models are in so they aren’t auto-registered. You can black list a whole namespace using the configuration method
ExcludeTypeFromAutoRegistration("Namespace.*")