explicit declaration does not override scan

56 views
Skip to first unread message

Raif

unread,
Mar 5, 2013, 9:21:46 AM3/5/13
to structure...@googlegroups.com

I have a registry that scans a couple assemblies. However, for some of those interfaces found it needs to use a specific class, not the one that implements the convention IMyObject -> MyObject.

so after the scan I say For().Use();

however in the AssertConfigurationIsValid Method it blows up saying bla bla bla MyObject bla bla bla. so for some actual code.

Scan(x =>
        {
            x.TheCallingAssembly();
            x.AssemblyContainingType<IUserRepository>();
            x.AssemblyContainingType<IDocumentDataService>();
            x.WithDefaultConventions();
        });
        For<ICommunityConfiguration>().Use<TestCommunityConfiguration>();

error is

Build Error on Instance 'HSTM.HLC.Common.CommunityConfiguration, HSTM.HLC.Common, Version=13.1.28.895, Culture=neutral, PublicKeyToken=0ecfe41405c30fb3' (Configured Instance of HSTM.HLC.Common.CommunityConfiguration, HSTM.HLC.Common, Version=13.1.28.895, Culture=neutral, PublicKeyToken=0ecfe41405c30fb3) for PluginType HSTM.HLC.Common.Interfaces.ICommunityConfiguration, HSTM.HLC.Common, Version=13.1.28.895, Culture=neutral, PublicKeyToken=0ecfe41405c30fb3

when I clearly asked for TestCommunityConfiguration. Some of these explicit overrides do seem to be working though which is kind of weird.

Any help would be appreciated.

Prabhjot Singh Saini

unread,
Mar 6, 2013, 6:09:02 AM3/6/13
to structure...@googlegroups.com
Why don't you try a remove (StructureMap.ObjectFactory.Container.EjectAllInstancesOf<>()) on the configured plugin type and then configure the new pluggedType. If you are using more than one pluggedTypes for the plugInType, then you might want to addInstances rather than add a DefaultInstance again.  

Regards,
Prabhjot



--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/structuremap-users/-/jY0RPnGxLxUJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jeremy Miller

unread,
Mar 6, 2013, 8:14:00 AM3/6/13
to structure...@googlegroups.com
Raif,

I think you need to look at the inner exception on that puppy.  "Build Error" just means there was an exception in the constructor function of your concrete class.

As for the overrides not working:

1.) I'm not sure I believe that, but I'll check it out this afternoon
2.) Worst case scenario is that you do your scans in the Initialize() block, then do your overrides in a Configure() block to guarantee that the timing happens at the right time.  Shouldn't be necessary, but there it is.

- Jeremy

Raif

unread,
Mar 6, 2013, 12:15:53 PM3/6/13
to structure...@googlegroups.com
Hi Jeremy, so this is what the WhatDoIHave() says I have

ICommunityConfiguration (HSTM.HLC.Common.Interfaces.ICommunityConfiguration) 7d1498c5-c9a0-469e-8cac-44c61c859748 
  Configured Instance of HSTM.HLC.Common.TestCommunityConfiguration, HSTM.HLC.Common.Test, Version=13.1.28.895, Culture=neutral, PublicKeyToken=0ecfe41405c30fb3                                        
Scoped as:  Transient

7d1498c5-c9a0-469e-8cac-44c61c859748 
Configured Instance of HSTM.HLC.Common.TestCommunityConfiguration, HSTM.HLC.Common.Test, Version=13.1.28.895, Culture=neutral, PublicKeyToken=0ecfe41405c30fb3                                        
HSTM.HLC.Common.CommunityConfiguration, HSTM.HLC.Common, Version=13.1.28.895, Culture=neutral, PublicKeyToken=0ecfe41405c30fb3
Configured Instance of 
HSTM.HLC.Common.CommunityConfiguration, HSTM.HLC.Common, Version=13.1.28.895, Culture=neutral, PublicKeyToken=0ecfe41405c30fb3   

after I do this 
 Scan(x =>
            {
                x.TheCallingAssembly();
                x.AssemblyContainingType<IUserRepository>();
                x.AssemblyContainingType<IDocumentDataService>();
                x.AssemblyContainingType<ILearningEventEditorController>();
                x.AssemblyContainingType<IUserSessionManagement>();
                x.ConnectImplementationsToTypesClosing(typeof(ILibraryRepository<>));
                x.ConnectImplementationsToTypesClosing(typeof(IValidator<>));
                x.AddAllTypesOf<IActivityContainerValidator>().NameBy(t => t.Name);
                x.AddAllTypesOf<IActivityElementRepository>();
                x.WithDefaultConventions();
            });

            For<IServiceLocator>().Singleton().Use<StructureMapServiceLocator>();
            For<ICommunityConfiguration>().Use<TestCommunityConfiguration>();

Looks like what Prabhjot said might work, but I'm not sure if this is how it's supposed to be done.
thanks,
Raif

Prabhjot Singh Saini

unread,
Mar 6, 2013, 12:25:56 PM3/6/13
to structure...@googlegroups.com
As per my understanding, if there is already a Default instance configured for a type, adding another default on top of the first one, definitely is an exception scenario. Overriding should be an explicit behavior and not the default one. If I need to override something, I need to explicitly tell the conatiner to do so. For semantics, we can see the same for virtual and overrides in C#. 

Regards,
Prabhjot. 

Regards,
Prabhjot



--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.

Raif

unread,
Mar 6, 2013, 4:25:54 PM3/6/13
to structure...@googlegroups.com
I'm willing to go that way, the problem is that Registry doesn't have a method for ejecting or overriding an interface.  I would have to have my bootstrapper scan all registries then come back and have a bunch of eject this and that and use this and that.  Seems a bit messy.

Regards,
Prabhjot



To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+unsub...@googlegroups.com.

To post to this group, send email to structure...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages