Autofac with internal objects behind a facade?

772 views
Skip to first unread message

Carl R

unread,
Jan 19, 2009, 5:52:07 AM1/19/09
to Autofac
Is it possible to use autofac with internal objects?
What i'm looking for is keeping most of a library's classes internal
with only a small facacde for utilizing it's functionality. I would
like all the internal classes to be loosely coupled and instantiated
with an IOC container internally triggered from the facade.
Is it possible? I just tested with ms Unity and it seemed that using
Constructor injection it wasn't possible with internal interfaces
being passed. What's the case with Autofac?
How would you go about in a similar situation where you want to hide
the internal classes making the public interface smaller but still
keeping it all loosely coupled?

Luke Schafer

unread,
Jan 19, 2009, 4:31:38 PM1/19/09
to aut...@googlegroups.com
Hi Carl,

Not sure exactly what you mean - I think either you want to expose only little bits of autofac through a facade (very simple, actually) and hence decouple it just that little bit more, or you want all your dependencies to be hidden. In the case of the latter - your interfaces must be publicly accessible, but your concrete implementations can be hidden.

Luke

Ben Taylor

unread,
Jan 19, 2009, 11:39:50 AM1/19/09
to aut...@googlegroups.com
This should work fine as long as you make sure either,
1.  Your container configuration code is in the same assembly as your internal classes.
Or
2. Your container configuration code is in an assembly that is marked as a Friend assembly of the assembly containing the Internal classes.  http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx



2009/1/19 Carl R <Carl.Rib...@gmail.com>



--
Ben Taylor
http://bentaylor.org/

Rinat Abdullin

unread,
Jan 19, 2009, 11:54:11 PM1/19/09
to Autofac
Hi Carl,

from my experience marking classes and interfaces internal just for
the sake of decoupling does not feel right.

I generally prefer another approach:

* Use namespaces to structure and hide component interfaces and
implementations from intelli-sense, unless needed.
* make all interface implementations explicit. This ensures that you
don't use classes for doing something (except for the testing) and
stick to interfaces.
* mark public constructors with ObsoleteAttribute (and set its
description "For IoC only"). This will ensure that you do not create
your classes anywhere in the production code (it is ok to do so in
tests).
* Set "treat warnings as errors" to ON for your production code
(generally a good thing anyway)


Best regards,
Rinat Abdullin

http://rabdullin.com
Reply all
Reply to author
Forward
0 new messages