StructureMap : How to define default constructor by code ?
        Posted  
        
            by cik
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by cik
        
        
        
        Published on 2008-11-14T08:34:54Z
        Indexed on 
            2010/03/13
            4:17 UTC
        
        
        Read the original article
        Hit count: 776
        
inversion-of-control
|structuremap
Hi,
I can't figure out how to define the default constructor (when it exists overloads) for a type in StructureMap (version 2.5) by code.
I want to get an instance of a service and the container has to inject a Linq2Sql data context instance into it.
I wrote this in my 'bootstrapper' method :
ForRequestedType<MyDataContext>().TheDefault.Is.OfConcreteType<MyDataContext>();
When I run my app, I got this error :
StructureMap Exception Code:  202
No Default Instance defined for PluginFamily MyNamespace.Data.SqlRepository.MyDataContext, MyNamespace.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
If I comment out all Linq2Sql generated contructors that I don't need, it works fine.
Update : Oh, and I forgot to say that I would not use the [StructureMap.DefaultConstructor] attribute.
© Stack Overflow or respective owner