IContainer.GetService<T>(bool) missing?

2 views
Skip to first unread message

Brian Chavez

unread,
Jun 18, 2008, 4:11:40 AM6/18/08
to linfufr...@googlegroups.com

Hi Philip,

 

Is there any particular reason why IContainer.GetService<T>(bool) is not defined?

 

Because, SimpleContainer.GetService<T>(bool) does exist.  Naturally, I would suspect that the (bool) overload should be present in IContainer too.

 

Please let me know if this is an inconsistency in the API.

 

Many thanks,

Brian

 

 


----------------------------------------------
Brian Chavez
Bit Armory, Inc.
http://www.bitarmory.com

 

Philip Laureano

unread,
Jun 18, 2008, 4:50:45 AM6/18/08
to linfufr...@googlegroups.com
Hi Brian,

The reason why the IContainer.GetService<T>(bool) doesn't exist is because the original intent was to have all containers return null if a particular service instance doesn't exist; however, there were some users who expected it to throw exceptions if the particular service instance type wasn't found, so I had to create an additional method which would let you decide on whether or not an exception should be thrown. That method was supposed to be internal to the SimpleContainer, but I figured that it might be useful to other users.

In any case, I've patched revision 133 to have that particular overload of GetService<T>(bool) in the IContainer interface. Enjoy!

Regards,

Philip Laureano

Brian Chavez

unread,
Jun 18, 2008, 6:03:34 AM6/18/08
to linfufr...@googlegroups.com

Hi Philip,

 

Thanks for the explanation!  That makes much more sense now!  I guess the reason I asked is because I'm finding it difficult to debug the Simple.IoC because I keep running into a problem.

 

I have the following scenario:

 

Assembly A:

    public interface IA

 

Assembly B:

    [Impelements(typeof(IA), Lifecycle.Singleton)]

    public class B : IA

 

Executing/Calling Assembly C:

    public class C{

           IContainer container = null;

          .ctor(){

               container = new SimpleContainer();

               Loader loader = new Loader( container );

               baseDir = AppDomain.CurrentDomain.BaseDirectory;

 

               loader.LoadDirectory( baseDir, "AssemblyB.dll");

          }

          IA GetIAService(){

               return container.GetService<IA>();

          }

    }

 

Now, if you notice, in C, I only load "AssemblyB.dll" in startup, but AssemblyB references a service interface in AssemblyA.dll.

 

I keep getting an exception like this:

{"Service type 'AssemblyA.IA' not found!"}            System.Exception {Simple.IoC.ServiceNotFoundException}

 

I also get the same exception when I forcefully load AssemblyA.dll in C (even though it doesn't have any ImplementsAttributes).

 

Am I doing this right?

 

Many thanks!

Brian

 


----------------------------------------------
Brian Chavez
Bit Armory, Inc.
http://www.bitarmory.com

 

Philip Laureano

unread,
Jun 18, 2008, 11:09:01 AM6/18/08
to linfufr...@googlegroups.com

Hi Brian,

Your code example for AssemblyA and AssemblyB looks correct, but the fact that you're getting a ServiceNotFoundException suggests a couple of things about CallingAssemblyC:

1. It has no references to AssemblyB since it's depending on interface IA for the implementation
2. Since CallingAssemblyC only references the interface IA instead of AssemblyB, AssemblyB.dll isn't being copied to the baseDir at build time.

My best guess is that if you add a post-build step that copies AssemblyB.dll to the target directory, you should get an implementation of interface IA without any problems once the loader sees AssemblyB.dll and loads ClassB into memory.

Go ahead and try it out, Brian, and let me know if it works. HTH :)

Regards,

Philip Laureano

Brian Chavez

unread,
Jun 18, 2008, 3:20:40 PM6/18/08
to linfufr...@googlegroups.com

Thanks for the guidance Philip.  After about 5 hours of debugging, I finally nailed it to a "service name" typo.

 

Thanks again,

-Brian

 


----------------------------------------------
Brian Chavez
Bit Armory, Inc.
http://www.bitarmory.com

 

From: linfufr...@googlegroups.com [mailto:linfufr...@googlegroups.com] On Behalf Of Philip Laureano


Sent: Wednesday, June 18, 2008 1:51 AM
To: linfufr...@googlegroups.com
Subject: Re: IContainer.GetService<T>(bool) missing?

 

Hi Brian,

Reply all
Reply to author
Forward
0 new messages