Have to register every class before the container can resolve?

377 views
Skip to first unread message

沈斌

unread,
Aug 5, 2010, 6:00:45 AM8/5/10
to aut...@googlegroups.com
let's say this scenario:

public class B {};

public class C
{
     public C(B b){}
}

To resolve C from Autofac container, I have to register both B and C to container.
But, today I used Unity, it seems I just need to register B to container, then C can be resolved.

So Autofac can't do as Unity do?
sorry for poor English.

Paul Stovell

unread,
Aug 5, 2010, 6:07:26 AM8/5/10
to aut...@googlegroups.com
This is possible with Autofac - see:


However, while it seems convenient, I think it's a bad feature to rely on. For example, Prism relies on some objects being resolvable (without registration), but since it doesn't register them, it never sets the lifetime. You can waste hours trying to work out why things aren't behaving as expected only to find out that an obscure piece of code assumed it had a transient but got a singleton. 

If you have lots of B's and C's, you could use Autofac's assembly registration syntax to find and register them all instead:


Paul




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



--
Paul Stovell
Reply all
Reply to author
Forward
0 new messages