StructureMap 2.6 (and 2.5.4) is Released!

Time flies when you’re having fun.  It’s been almost a year since I’ve made an official StructureMap release, so I guess it’s about time.  This morning I uploaded the binaries for the 2.6 release.  This release just adds some bug fixes and a couple minor additions to the 2.5.4 release that I made in December but didn’t really publicize.  The release notes below are long, but that’s because they represent almost a year’s worth of development.  As I said yesterday, StructureMap is most likely moving to GitHub with the documentation going as well.  After a massive effort to write documentation early last year, huge chunks of it is already obsolete and there’s been a lot of addition since.  I’m hoping that the move to the Wiki will make it easier to keep the docs up.  In the meantime, I’ll try to blog a bit about the newer pieces starting tomorrow.

A tiny bit of history.  This is the 11th StructureMap release since it debuted way back in June of 2004.  Almost nothing is the same.  We use it differently, the expectations are different, and very, very little of the original code survives today.  At QCon San Francisco in 2008 I talked about what I’d learned from evolving this codebase over so many years and changes.

This release includes a lot of patches from the community, and I’d like to thank all of you for that – especially Frank Quednau and Andreas Ohlund for taking on some nastier things.  Josh and Kevin Miller do yeoman duty answering StackOverflow questions (so I don’t have to). 

 

What’s Changed?

  • New terse, “jQuery-esque” syntax for the Registry DSL.  Let’s just write off “ForRequestedType<IFoo>().TheDefault.Is.OfConcreteType<Foo>()” as a well meant experiment, shall we?  It’s still in the codebase, but it’s marked as [Obsolete].  Nobody liked it and I thought it was annoying in real life usage.  Now, just do:  For<IFoo>().Use<Foo>();  My whole goal was to reduce friction.  Needs a big blog post
  • Changed the Registry DSL to make inline dependency configuration be more consistent.  Definitely a blog post.
  • The “CreateProfile” syntax has gotten a lot of complaints for being inconsistent with the rest of the Registry DSL.  I basically rewrote it to now be consistent with the “For<>().Use()” syntax in the main Registry DSL.  Blog post coming soon….
  • Nested Container feature for short lived transactional requests.  I built this for Dovetail usage, but I think it’s my preferred way to manage object scoping in certain circumstances.  I mentioned it just a little bit in my NHibernate w/ StructureMap post a couple weeks back.  Blog post coming soon…
  • The “Model” feature was completely redone.  There’s a lot more power, and you can use it to pull services out of the Container and completely remove services from the Container as well.  Sigh.  Needs a blog post.
  • Convention based type registration got a lot of work.  People are pushing this feature very hard and it had to grow.  You can now use the Registry DSL to write conventions.  This was improved farther in the latest code drop.  Yeah, blog post coming…
  • Better support for registering services by Type objects for cases when you don’t necessarily know the Type upfront.  Big request from several framework authors like Caliburn.
  • A helluva lot of new features to make working with open generic types easier.  Jimmy Bogard blogged about some of it here.  I’d like to show how StructureMap’s new features would make writing something like Davy Brion’s Agatha framework a snap.  I use this stuff extensively inside of StoryTeller.
  • Added the lazy Func<T> feature from Autofac.  A really great (and cheap) way to support lazily initialized components.  Blog post coming.
  • Completely ditched all Reflection.Emit code.  StructureMap now strictly uses dynamically constructed Expression’s that are pre-compiled into cached Func’s.  I don’t know if that really makes much difference to users, but it makes StructureMap much, much easier to extend.  The container does spin up faster with this mechanism.  Makes me happy.
  • Supports IList<T> and List<T> arguments.  It works just like Arrays.  That’s been a while coming.
  • You can set the lifecycle from <AddInstance> if you happen to still use Xml configuration. 
  • The “Lifecycle” code was completely reworked to eliminate shared code
  • Container.Dispose() was introduced.  I’ve put a lot of effort into making StructureMap clean up after itself.  Definitely a blog post coming.
  • ObjectFactory.Container.  Slowly, but surely, I’d like to wean people away from using ObjectFactory too much in favor of scoped Container objects.  I will NOT be further extending the ObjectFactory static methods to synchronize it with IContainer.  Instead, I’m just exposing the ObjectFactory.Container property.
  • New abilities for IContext like BuildUp() (thanks to Kyle Malloy), getting all instances, and TryGetInstance
  • TryGetInstance() from Josh
  • Killed StructureMapConfiguration.  Good riddance.
  • “Forwarding” requests for IFoo to whatever IBar is

About Jeremy Miller

Jeremy is the Chief Software Architect at Dovetail Software, the coolest ISV in Austin. Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy is the author of the open source StructureMap tool for Dependency Injection with .Net, StoryTeller for supercharged acceptance testing in .Net, and one of the principal developers behind FubuMVC. Jeremy's thoughts on all things software can be found at The Shade Tree Developer at http://codebetter.com/jeremymiller.
This entry was posted in StructureMap. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://fknet.wordpress.com/2010/03/11/structuremap-v2-6-1-released/ Frantisek

    We migrated from 2.5.4 to 2.6.1 and here are some of my comments, especially for Singleton(), OfConcreteType and Unit tests.

    http://fknet.wordpress.com/2010/03/11/structuremap-v2-6-1-released/

  • http://realfiction.net Frank Quednau

    For those concerned with the performance implications of removing the Emit code, here’s a little comparison of 2.5.4 to 2.6.2: http://realfiction.net/Content/Entry/156

  • Ollie Riches

    Congrats – the new ‘For’ is priceless…

  • David Kemp

    Thanks for this. It’s shorter and sharper and nicer.

    The only gripe I have is where the AsSingleton/Singleton method comes:

    For().Singleton().Add();

    For me, the Singleton() invocation makes after the Add, as it defines the cope, eg:

    For().Add().AsSingleton();

    However, at least it’s consistent in this release, so thumbs up for that!

  • Kenny

    Just upgraded to 2.6, works like a charm, looking forward for your post on ObjectFactory.Instance usages.

  • http://codebetter.com/members/jmiller/default.aspx Jeremy D. Miller

    @Thomas,

    I’m not going to keep updating ObjectFactory itself. I’m advising you to either use ObjectFactory.GetInstance<>() once and only once, or to use either an injected IContainer or ObjectFactory.Container.

    I’ll blog this soon w/ real code samples.

  • Thomas

    You said that ObjectFactory.Container will not be extended. What’s the besr practice to not use it. I always used it so would like to know what you recommend ?

  • http://realfiction.net Frank Quednau

    Great stuff, Jeremy! Your blog post list is a daunting task :) I’d be happy to help moving SM to the github, maybe some of those posts may as well become Wiki pages.

  • http://hex.lostechies.com Eric Hexter

    Congrats, that is an impresive list.

    I would just like to say thank you. I look forward to the new registration syntax.

  • http://darrell.mozingo.net Darrell Mozingo

    Congratulations! We’ve been using StructureMap for quite a while now and love it.

    Keep up the great work you and all the contributors do for the community. We appreciate it.

  • http://codebetter.com/members/jmiller/default.aspx Jeremy D. Miller

    @Ravi,

    The Func’s are compiled and cached. Besides, it’s not completely about perf. The Emitting is brittle and difficult to change. It stopped innovation at several points.

  • http://rterala.blogspot.com Ravi Terala

    Just curious.. isn’t code generated through dynamic expressions slower than Reflection.Emit? I vaguely remember a blog post from some one who tried this approach vs Reflection.Emit and found it to be slower.

  • http://blog.zoolutions.se Mikael Henriksson

    Thank you Jeremy,

    I am really happy with the changes. I am so happy with the changes that I created my own StructureMapBuilder for NServiceBus to be able to take advantage of the changes in my project.

  • http://codebetter.com/members/jmiller/default.aspx Jeremy D. Miller

    @BjartN,

    Dovetail has been running on the trunk for the entire time and we hit most of the functionality. I might remove the obsolete methods later this year, but I think I’m just about done with SM for a while.

    There will inevitably be a 2.6.1 release soon with bug fixes because that’s just the way it works.

  • http://bjarte.com BjartN

    Nice to get rid of the ForRequestedType().I.Try.To.Make.English.Sentences.OfConcreteType() feature.

    Can you say anything about the stability of this release ?

  • http://blog.fohjin.com Mark Nijhof

    Congratulations on a great release, many new and cool things that will make our lives yet so much easier.

    -Mark

  • Charles Strahan

    Congrats man! Thanks for creating such an awesome tool.

  • http://davidthieben.com dave.t

    Jeremy, it’s great to see progress on such a great tool.

    I was wondering if you could point me to, or perhaps write a blog post about, the best-practice usage for the IContainer, and how best to “wean people away from using ObjectFactory too much in favor of scoped Container objects”.

    thanks for all your hard work!

    dave.t

  • http://chadmyers.lostechies.com Chad Myers

    Congrats Jeremy, this is huge! Here’s to 11 more!

  • http://www.codeofrob.com Rob Ashton

    I’ll be upgrading pronto for the improved open generic type support.

    (And trying to reduce some of our manual setup with more conventions so I’m not so afraid of upgrading in the future ;-))