Re: An issue regarding to IConstructorFinder in changeset #1155

27 views
Skip to first unread message

Alex Meyer-Gleaves

unread,
Apr 26, 2013, 8:37:02 AM4/26/13
to aut...@googlegroups.com
Hi Jing,

I wrote the following unit test to find the problem but instead found that it passes.

public class CustomConstructorFinder : IConstructorFinder
{
public bool FindConstructorsCalled { get; private set; }

public ConstructorInfo[] FindConstructors(Type targetType)
{
FindConstructorsCalled = true;
return new DefaultConstructorFinder().FindConstructors(targetType);
}
}

[Test]
public void FindConstructorsWith_CustomFinderProvided_CustomFinderInvoked()
{
var builder = new ContainerBuilder();
var finder = new CustomConstructorFinder();
builder.RegisterType<object>().FindConstructorsWith(finder);
var container = builder.Build();

container.Resolve<object>();

Assert.That(finder.FindConstructorsCalled, Is.True);
}

Are you doing something different to what this test is covering?

Cheers,

Alex.

On Friday, 26 April 2013 16:25:06 UTC+10, Jing Wu wrote:
Hi,

In commit 1155, it changed the constructor finder to be called in constructor of ReflectionActivator.
"Invoke the IConstructorFinder in the constructor of ReflectionActivator and keep the result in a field instead of invoking on each call to ActivateInstance."

It breaks my code in which I replaced constructor finder for my type, and the replaced constructor never get executed.


Cheers,
Jing

Alex Meyer-Gleaves

unread,
Apr 27, 2013, 8:33:29 AM4/27/13
to aut...@googlegroups.com
I see now. I'll write up another unit test and if necessary rollback the change. The change was related to performance tuning and is not critical in any way. Keeping existing functionality working is more important. I should be able to get to that tomorrow.

On Saturday, April 27, 2013 10:26:31 PM UTC+10, Jing Wu wrote:
Hi Alex,

You are right that IConstructorFinder.FindConstructors is executed. And I finally found what causes my issue.
In commit#1155, it actually changed the execution order of below functions:
1. IConstructorFinder.FindConstructors
2. Module.AttachToComponentRegistration

My IConstructorFinder.FindConstructors relies on some data constructed in Module.AttachToComponentRegistration, I assume these two method happens in reversed order.

Do you have any idea?

Cheers,
Jing

Alex Meyer-Gleaves

unread,
Apr 28, 2013, 7:08:21 AM4/28/13
to aut...@googlegroups.com

I had a look at this and both configuring the module and creating the registration are calls made through configuration callbacks (executed when the container is being built). This means that the order they are added in is the order they will execute in.

 

If you configure your module registration on the container builder before adding the registrations that have FindConstructorsWith, the execution order will allow your code to work.

 

Please let me know if this works for you. I suspect that your particular scenario is probably not very common and I would like to keep the performance optimization if possible.

--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autofac+u...@googlegroups.com.
To post to this group, send email to aut...@googlegroups.com.
Visit this group at http://groups.google.com/group/autofac?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages