D'Arcy from Winnipeg
Solution Architecture, Business & Entrepreneurship, Microsoft, and Adoption

Sub Sonic - The Great DAL Debate!

Sunday, December 30, 2007 3:02 PM

[Edit]

This post has generated a lot of buzz, spawned some great discussion and even a full length article on how to set up Sub Sonic as a stand-alone assembly. For the reader stumbling on this post via Google or what not, please ensure you read the full comments on this post. Also, ensure that you check out Willie's tutorial on how to set Sub Sonic as a standalone DAL.

Finally, to see how this ended up and where the conversation is leading, check out my follow up post here.

D'Arcy - January 4/2008

[/Edit]

I've become disenchanted with Sub Sonic. Well...not entirely disenchanted: what it does it does very well. If you want to couple your web application's DAL and Logic tiers into the same web-app assembly, with only namespaces acting as logical borders to the components, then go nuts. Sub Sonic is definately the tool for you.

But although I've appreciated using Sub Sonic's ability to create my DAL and entity objects quickly, there's one glaring issue that is just a huge problem for me...HUGE...as in, deal breaker. As in, if you want to architect an application with proper separation of responsibilities, you just can't do it with Sub Sonic.

I wanted to take my generated classes and put them into a separate assembly library. Why? Seriously, you're asking that? You shouldn't...you should know that you should ensure that all your code is highly cohesive and loosely coupled...you should make sure that your UI layer doesn't know anything about the database implementation, providers required, or connection string. For that matter, your business/logic/whatever-you-call-it tier shouldn't know any of the database stuff either...that's why it's called a DAL: its the DATA ACCESS LAYER.

Ok...rant done.

So I've been beating my head on my desk because for the life of me I can't realize why I keep getting the error:

"Can't find the SubSonicService in your application's config"

What do you mean you can't find it?! It's right there...I can see it...the section is THERE.

Alas, it matters not...because it will never read it from there. It will never look there, it doesn't even care that there's a config file associated with the library.

All it knows is that it needs to find the SubSonicService section in the Web.Config section. This was cemented by a post I found on the SubSonic forum where "spookytooth"...

[Edit] ahem...who happens to be "Rob"...who happens to be the main guy *behind* Sub Sonic...yeah...[/Edit]

who happens to be a SubSonic team member as well as on the ASP.NET team, clarified that indeed the execution environment is the web, and therefore the SubSonic dataservice will be looking for a web.config file to pull the values out.

[Edit] Took out this part because it was a misunderstanding between what I *thought* Rob was trying to say and what he meant...he explained it in the comments. [/Edit]

Look, SubSonic is a great tool if you want to create a web or windows based application that you fully expect to be tightly coupled with the data access and entity layers. But if you're looking for something with more flexibility, you're better off using other code generation tools that do the same thing as SubSonic without handcuffing you to their data service components.

[Note: strong ending statement...read the comments below for the full conversation]

D




Feedback

# re: Sub Sonic - Look, its not me...its you!

Nice.

But that is so not true that you can't use SubSonic as DAL for a N-tier application with proper separation of responsibilities.

I got that to work with no problems.


/*"Can't find the SubSonicService in your application's config"*/
The only time I found this error is when using a Custom Control

and the config settings you can use the app.config you don't have to use web.config 12/30/2007 9:38 PM | yitzchok

# re: Sub Sonic - Look, its not me...its you!

/*"Can't find the SubSonicService in your application's config"*/
The only time I found this error is when using a Custom Control **** In Design Mode **** 12/30/2007 9:40 PM | yitzchok

# re: Sub Sonic - Look, its not me...its you!

Hmm...you'd have to expand on how you got it to work.

The error I'm getting has nothing to do with a custom control...in fact, it has nothing to do with any control. I have three seperate projects in my solution:

Application.Web
Application.Controller
Application.DAL

The DAL is my SubSonic generated code put into a seperate assembly. Whenever I try to access the database (via one of the generated objects or with a stored proc), it errors out from the DAL layer...and that's with an app.config file as part of that project.

The only way I can avoid the error is to move the SubSonic config portions into the Web.Config file of the Application.Web project.

If you could shed some light on how to make the assembly work *without* having to duplicate the config info into a web.config file, that would be great!

D
12/31/2007 1:19 AM | D'Arcy from Winnipeg

# re: Sub Sonic - Look, its not me...its you!

Sounds to me as if the problem is caused by the .Net class library and not SubSonic. You assembly is executing in context of a web app, and as such I would expect all assemblies to look in web.config for configuration information. In fact, if you look through the System.Configuration classes you will see that the configuration manager determines whether to look in an app.config or the web.config based on the current execution environment. So Rob (aka SpookyTooth) is absolutely correct when he says that "The execution environment is the web, so you need to have the bits setup in web.config." This is not something in SubSonic's code, but rather the .Net library. 12/31/2007 6:52 AM | Joe Brinkman

# re: Sub Sonic - Look, its not me...its you!

No, its SubSonic.

If I was just dealing with straight .NET classes, then I could use a .settings file to generate the config values for the assembly and access them through either the My or Properties keywords from my assembly.

But with SubSonic, its married to the .NET Configuration classes and there's no way to re-wire it to use an alternate source of config settings. Even if I wrote my own custom config library, there's no obvious way for me to go in and wire that up without downloading source code and making modifications.

And my issue with Rob wasn't disputing what he said technically...it was his comment about it being "just text"...the fact that there's this attitude (and not just him specifically, but in web-devs in general) that seperation of responsibility/concerns is just some extremist idea that doesn't have any relevence to every day development.

D 12/31/2007 10:11 AM | D'Arcy from Winnipeg

# re: Sub Sonic - Look, its not me...its you!

Funny I was just going to ask who the extremist here is.

1. Rob for building a useful tool for the community and never claiming anything more than it is or how it works.

2. A developer telling Rob how he should have built HIS tool properly and ranting off on design, architecture, his attitude, blah, blah, blah.

I guess another “Rock Star” is born.

- willyd
12/31/2007 11:16 AM | William

# re: Sub Sonic - Look, its not me...its you!

Wow...did someone tinkle in your cornflakes this morning Will?

I never said that SubSonic was a bad tool. I even stated:
"Look, SubSonic is a great tool if you want to create a web or windows based application that you fully expect to be tightly coupled with the data access and entity layers."

but my hope was that I would be able to use the tool in a true seperation-of-responsibility type of layout. Out of the box, that doesn't occur.

And I do disagree with the statement that was made about "just text" being thrown around, but last I checked this was a free-internet where you could disagree. I wasn't trashing the guy, just pointing out a comment that I disagreed with.

If I was truly looking for Rock Star status, I would have made a smart-ass comment about DNN as well to get Joe riled up.
;)

D 12/31/2007 12:29 PM | D'Arcy from Winnipeg

# re: Sub Sonic - Look, its not me...its you!

you can most definitly use subsonic as a straight up dal in a seperate assembly. In fact I prefer this. I just run the subcommander to generate the classes into a seperate probject, and reference the subsonic dlls in it (I also trim down subsonic to remove web specific stuff for this).

There is even a screencast out there on doing this. 12/31/2007 1:16 PM | Mike Wolf

# re: Sub Sonic - Look, its not me...its you!

Mike, I realize you can do this...but can you do it without having to specify your connection string (and all SubSonic config pieces for that matter) in your web.config file? That was the issue I had.

Thanks!

D 12/31/2007 1:35 PM | D'Arcy from Winnipeg

# re: Sub Sonic - Look, its not me...its you!

http://forums.subsonicproject.com/forums/p/2382/10183.aspx#10183

I don't that there is a problem with seperation of concern when you put the config in the app that is actually running the code the dll's are just Class Library's and your main app(website) runs them. it can't do nothing by them self.

Maybe there should be a way to put that information in the "AllStructs" file(or somewhere else) and if it doesn't find it in all other places then it should look there.

------------

The configuration is taken from what the .NET framework gives it so there is where you have the same problem with the custom control loading in design time as the main application is devenv.exe
not the root of your project or the bin directory 12/31/2007 2:31 PM | yitzchok

# re: Sub Sonic - Look, its not me...its you!

http://msdn2.microsoft.com/en-us/library/a65txexh(VS.80).aspx


Because there is no configuration file model for class libraries, application settings do not apply for Class Library projects. The exception is a Visual Studio Tools for Office DLL project, which can have a configuration file. 12/31/2007 7:38 PM | yitzchok

# re: Sub Sonic - Look, its not me...its you!

Hey D'Arcy - sorry you're having issues. Lets see if we can help out here...

>>As in, if you want to architect an application with proper separation of responsibilities, you just can't do it with Sub Sonic.<<

You indeed can - wouldn't have made something that wasn't able to do this very simple thing.

>>Alas, it matters not...because it will never read it from there. It will never look there, it doesn't even care that there's a config file associated with the library.<<

As I explained in the thread referenced - you can't pull a config (without some gymnastic coding) "into an assembly" - the execution environment reads the config, and assigns it as necessary to every DLL in its /bin. This includes SubSonic and your DAL.

If you use SubSonic, it looks for this config setup in your executing app's root (app or web.config). It will not use one that you include in your class lib because that's not how .NET works (see the link above).

>>>It's just text. Just text. Who cares where it is. Hell, why don't we just throw away everything we've developed around OO programming and go back to writing spaghetti code...because code, developed in either method, is "just text", isn't it?<<<

:) - I think you're confused regarding the subject of the post that you referenced - and this is my fault. I should have added some explanation here.

First - if you use our Command Line tool, we do indeed look for an App.Config in your class lib's root (if you create a separate project). Most people don't put a config file in their class lib root because it never gets read and is sort of pointless.

However, if you want to generate your DAL, as a convenience, we will look for and read a config file for your DAL - and you can place this in your class lib root. My comment RE "it's just text" was in response to criticism of doing this - most people would expect that our command line tool should read from the main project's config.

This approach won't work, however, since each class lib using SubSonic may have separate config settings - so I decided to make it a convenience thing to use a config file for each project - if you want. You can pass in, if you choose, all the stuff to the generator via command line.

Finally - I apologize if you didn't get your answer in our forums. I've been trying to make it easier for people and... well it's not so easy :). I hope you understand what me (and others here) are saying, and perhaps in the future you can get the help you need before frustration moves you to write a post :).

Email me (on the comment) if you have any more questions. Architecture is a major concern of mine, and I'm pretty particular about this stuff :).

Cheers,
Rob

12/31/2007 9:15 PM | Rob Conery

# re: Sub Sonic - Look, its not me...its you!

I think we're struggling with a simple misreading of Rob's forum post. The statement "the execution environment is the web" describes the original poster's app, not all apps that use SubSonic. I understand the concern about duplicating the content of the config file, as the app's config could easily get out of sync with the one used to generate the DAL, but that is not the same issue as D'Arcy's separation of responsibilities.

Regardless of which tool you use, your configuration file IS going to be coupled to your implementation. For example, the membership provider and connection string must be in the app's config file.

Regarding separation of concerns, can you not use SubSonic in an MVC structured app, thereby keeping the view (whether it be web or Windows) totally ignorant of the model uses SubSonic entities? How the controller's code would not be coupled to SubSonic, that is another story. The best I can think of is that some IoC container should hand the controller interfaces which just happen to be SubSonic implementations. But all that seems like a lot of extra code, which doesn't really match Rob's stated objectives for SubSonic. 1/1/2008 8:26 AM | flipdoubt

# re: Sub Sonic - Look, its not me...its you!

Hey Rob,

Thanks for posting the comment...I *think* I see where the disconnect has come in, but I'm going to go back and test the command line tools like you suggested to make sure that what I think you're saying is what i was looking for in the first place.

D 1/3/2008 12:22 AM | D'Arcy from Winnipeg

# re: Sub Sonic - Look, its not me...its you!

I don't follow this post at all. I have all of my generated subsonic files, along with all data access methods within it's own assembly. Sounds like you simply have a configuration error. In fact, in one of my projects I have 2 separate assemblies for the "highly cohesive and loosely coupled" factor. There is no code overlap in either, and I'm able to have web app, win app, web services projects access my abstracted dal just fine... 1/3/2008 2:45 PM | Willie Tilton

# re: Sub Sonic - Look, its not me...its you!

Do you have your connection string information solely in your DAL, and not in the configuration files specific to your web app, windows app, and web service?

If you do, then obviously that is the piece that I'm missing, as that's the scenario I want to achieve but didn't think SubSonic could do.

D 1/3/2008 3:02 PM | D'Arcy from Winnipeg

# re: Sub Sonic - Look, its not me...its you!

I do, you simply use the "Copy always" option within your DAL. I outlined how I have my project setup here: http://blechie.com/wtilton/archive/2008/01/03/340.aspx 1/3/2008 3:43 PM | Willie Tilton

# re: Sub Sonic - Look, its not me...its you!

>>>Do you have your connection string information solely in your DAL, and not in the configuration files specific to your web app, windows app, and web service?<<<

Your DAL is a component of your overall application and as such, ascribes to the application's configuration. If your DAL had it's own configuration, it would be an application in and of itself.

You can create a subsonic.config file if you like (but it still needs to live in the app root) and reference it by file if that helps you here - but in general, no you can't keep a separate config in your DAL.

If you wanted to hard-code it, that's another issue. But I don't recommend that.

Finally - when you solve this issue I'd appreciate an edit :). Google can be unforgiving... 1/4/2008 12:48 AM | Rob Conery

# re: Sub Sonic - The Great DAL Debate!

The only normal way to do it is implement your own configuration reader something like nHibernate uses but from the .NET configuration you can only load it from a file.

And if it is not the (app).exe.config or web.config then you will have to tell it some way where it is and load it manually (SubSonic uses this).

I didn't find a way in the whole .NET framework(and I tried google) to load it from a text string or embedded Resource file.

One problem is that the configuration class has a private constructor so you must use one of there Static methods to get a Configuration object(maybe for security reasons):| 1/6/2008 6:24 PM | yitzchok

Post a comment