Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool



Notes from upgrading from StructureMap 2.4.9 to StructureMap 2.5.0

Tonight I updated the Dimecasts codebase from the 2.4.9 version of StructureMap to 2.5.0 and ran into few scenarios where some 'hefty' changes were required.  I thought I would share the 2 major areas that needed change.

Adding named concrete instances for a given interface:

Was

AddInstanceOf<IAddin>().UsingConcreteType<DotNetKicksAddin>().WithName("DotNetKicks");

Is

ForRequestedType().AddInstances( x =>
                                    {
                                        x.OfConcreteType().WithName( "DotNetKicks" );
                                        x.OfConcreteType().WithName( "DZone" );
                                        x.OfConcreteType().WithName( "Digg" );
                                        x.OfConcreteType().WithName( "ShareThis" );
                                    }
                );

 

Registering Registry's at application startup:

Was

StructureMapConfiguration.AddRegistry( new IoCWebRegistration() );

Is

ObjectFactory.Initialize( scanner =>
	{ 
		scanner.AddRegistry( new IoCWebRegistration() );
		scanner.AddRegistry( new IoCDomainRegistration() );
		scanner.AddRegistry( new IoCRepositoryRegistration() );} 
	);


 Till next time,

[----- Remember to check out DimeCasts.Net -----]



Comments

Steven Harman said:

Curious,

Why register the registries explicitly as opposed to just scanning for them?

# October 21, 2008 10:49 PM

Derik Whittaker said:

@Steve,

The main reason I do not use the 'scan' feature is because I would rather register everything explicitly.  If all things are equal I always lean towards making code more explicit rather then less.

Also, In the eyes of many there is already enough 'black magic' in IoC containers and having the framework 'just find' registries would be considered 'magic'.  -- Not saying that I believe this is magic, but some do.

With all that being said, you do have a valid point.  I could simply tell SM to scan and be done with it.  That is a valid option.

# October 22, 2008 6:12 AM

Nick berardi said:

Is there any reason they made the interface more verbose?  Or was that you making more explicit code, like you were explaining to Steve?

# October 22, 2008 8:19 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Derik Whittaker

Derik is a .Net Developer/Architect specializing in WinForms working out the northern suburbs of Chicago. He is also believer and advocate for Agile development including SCRUM, TDD, CI, etc.

When Derik is not writing code he can be found spending time with his wife and young son, climbing on his bouldering wall, watching sports (mostly baseball), and generally vegging out. Check out Devlicio.us!

Our Sponsors

Proudly Partnered With


This Blog

Syndication

News