question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Locate ignores extraData

See original GitHub issue

Grace 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:closed
  • Created 4 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ipjohnsoncommented, Dec 4, 2019

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.

1reaction
ipjohnsoncommented, Dec 4, 2019

@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.*")

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found