views:

73

answers:

1

Hi

Does anyone know how to have dependency injection work with linq2sql. Heres my situation..

I will explain it as best i can here.

I have a base class which has a DBML (linq2sql) and classes etc .. This DBML is COMMON to more than 1 project.. Well each project has its own DBML but has all the tables etc that is in the common dbml i am using in the base class - does that make sense?!

Each of my projects creates a new class by inheriting the base class and extending it... but of course i need to REINJECT my dbml because the dbml that i use specifically in my project has all the functionality that was in COMMON and then some

I am a little lost here.. Anyone know how to achieve this.. I do hope i explained it well enough :-)

I was hoping to use unity or something similar, the classes that are created by linq2sql don't seem to implement interfaces... is this going to be a issues with DI?

Thanks

+1  A: 

It sounds like you probably don't need a DBML in every project. I would recommend having one project "MyCoolApp.Entities" that contains your Linq to SQL entities, and then reference that project in your other projects. Those other projects can extend your base entities as needed.

As for Dependency Injection, Unity can definitely resolve dependencies that don't implement interfaces so that shouldn't be a problem.

free-dom
+1 - For suggesting moving the DLINQ to a common project that can be used by other projects.
James Black
Ok .. thanks for the 2 comments, just thinking out loud... but i need the class datacontext when i am working with my linq... so hence my base project is going fail isn't it ?? ...
mark smith
You can use the datacontext from the "MyCoolApp.Entities" project in your other projects.
free-dom