entity framework 6 - StructureMap - Default constructor blues -


i'm going crazy got this

public class frameworkdbtestbase : idisposable {     protected readonly frameworkdb db;     public frameworkdbtestbase()     {         var connection = effort.dbconnectionfactory.createtransient();         db = new frameworkdb(connection);     }      public void dispose()     {         db.dispose();     } } 

this mocking ef6 effort .. love can continuously perform tests in background while changes happening against codebase ... great unfortunately need

public partial class frameworkdb : dbcontext {     public frameworkdb() : base("defaultconnection"){}     public frameworkdb(dbconnection connection): base(connection, true)     {         configuration.lazyloadingenabled = false;     }      public dbset<site> sites { get; set; } ... 

in order mocking of ef6 effort going structuremap insists on creating me frameworkdb instance long constructor 1 dbconnection injection parameter this:

structuremap.structuremapexception unhandled user code   hresult=-2146232832   message=structuremap exception code:  202 no default instance defined pluginfamily system.data.common.dbconnection, system.data, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089   source=structuremap   errorcode=202 

sigh! roll eyes ... want structuremap use me other shorter constructor after digging according post: structure map - dont want use greediest constructor! should change this:

for<frameworkdb>().use <frameworkdb>(); 

to this

for<frameworkdb>().use(() => new frameworkdb()); 

no such luck still same error ... , dont want remove connection constructor else integration test wont work anymore... maybe uses connection construct mapping , not use in injection ... no such luck ... adding this:

for<dbconnection>().use(() => new entityconnection("defaultconnection")); 

gives me that:

structuremap.structuremapexception unhandled user code   hresult=-2146232832   message=structuremap exception code:  207 internal exception while creating instance '00fbcc4f-c5f0-4eb3-b814-9d0ba1bb8e19' of plugintype system.data.common.dbconnection, system.data, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.  check inner exception more details.   source=structuremap   errorcode=207 

well theory... ahum... solution anyone? hellooo anyone? sigh ...

come on people no one? answer simple ... well

var framework = new framework(); for<frameworkdb>().use(() => framework); 

so simple yet elegant , have know!


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -