Best Practices for n-tier on .net 2

Hello. I usually in asp.net 1.1 make my web application, then I created a class library in which one I put my objects like (persons, authors, books, etc).
In another class library I put my Data Access Logic Layer, this one is used by the above class library.  and the object class library is used by the web application.

How this should be done in asp.net 2.0 I tried to make a class library but I cant add a web.config to that classlibrary to put the connection string so where do you recommend me to put it

Now that theres one folder more called app_code When Should I put my classes there and when should I put classes on a class library project  

It seems to be that the N-tier now is more logical than physical partitioned, as I have seen some examples and everybody puts their classes on the app_code directory and not on a class library.


Thanks all experts for your opinion,


Answer this question

Best Practices for n-tier on .net 2

  • FatherDrew

    Just like .NET 1.1, you put your settings in web.config in the web application's root directory.   It doesn't go in the bin subdirectory, and it doesn't have the name of the DLL.
  • Mark Peterson

    Bento,

    Would you mind sending in the code so that I can analyse and test it myself

     

    Lakshmikanth Upadrasta

     



  • dparvin

    Luis,


    My understanding is that App_code folder is basically for writing custom code for ASP.NET pages to access the tiers beneath the ASP.NET UI/Presentation. Next thing, N-tier has been logical ever since and not physical (as in deploying on seperate machines or different projects). It depends on the size of the project and what kind of scalability you are looking for.

    One approach to re-solve your issue is to put a XML configuration file in the bin folder from where your Data Access Layer runs and have the connection string specified there.  This way your are still keeping the DAL code and database connection string seperate from the other layers.

    Hope this helps. Happy coding.


    Regards
    Lakshmikanth Upadrasta

  • KatherineG

    I changed the way I implemented the connection setting for my app.
    Instead of using the assemblies app settings, I've move the settings to my Web.Config and added the connection string there. It makes sence. It would be cool if refering an assembly copies the required setting entries.

    Thanks for your help .


  • Freddie Tripples

    .net 2.0 allows you to create app config files for any kind of project, such as class libraries, 1.1 only allowed to do so on web application/web services project or or projects whose output was an .exe.

    can can just right click on the project and choose properties, then choose the configuration file and click on create application settings.

    The only problem with this approach is that it will include the configuration file within the .dll, meaning, you won't have a separate .xml file that you can modify to change your connection string (therefore, you must recompile the class library and redeploy the .dll).

    You do have an xml file in your project directory, but it's only used by the compiler, the .dll will ignore it.

     

    app_code is used for the case you want to include classes (like .cs or .vb files) in your web application without creating a separate class library.

    Unlike 1.1 where you could mix different type of files in your web application, you can't do that on 2.0, so they provide you that asp.net special folder to storage your code files.

    The decision to put your code files there or on a separate class library is yours, 2.0 allows both choices.

    Don't follow the sampes too closely, only as a general guidance, they do it that way only because it's quicker and easier, but it doesn't mean it's the only or the best way.

    When you choose the option "create web site" the compiler will take care of placing your .dlls where they should be (the app_code) folder, 2.0 does not create a .dll for your web application as 1.1 does, asp.net builds them on the fly in 2.0.

    You can then use the copy website command and it will take care of copying all the files you need in the appropriate places for it to work.

    I am not an expert but I hope it helps.

     


  • John Jordan

    I've tried doing just that with no success. What I did is place the app.config file for my data layer, renamed like my compiled DLL and added the "config" extension, placed it in the BIN folder of my WebService and it's still not reading the settings from the file.
    I'm not sure what's wrong here. In Net 1.0-1.1 it was enough to put the an entry with the same name in the main application's configuration file and any refered DLL would look for it's settings there. Sure it wasn't perfect but at least it worked. I'm thinking that if the DLL should read it's settings from a file, it should be automatically copied along with it when I reference it (like it does with the compiled assembly itself).

    Any suggestions are welcomed.

  • Best Practices for n-tier on .net 2