0

I have the following solution structure:

Portal.DataAccess -> Class library project with methods against database...

Portal.DomainEntities -> Class library project (Where i have my storage classes)

Portal.Business -> class library (proxy between front end and data access)

Portal.Web -> class library with references to web context (system.web.mvc, etc...)

Portal.Web.Website1 -> My website 1

Portal.Web.Website2 -> My website 2

....

Portal.Web.WebsiteN -> My website N

All my websites uses the same queries, and i would like to create a file with the following structure:

<?xml version="1.0" encoding="utf-8" ?>
<Queries>
      <Query>
        <Name>DetailArticle</Name>
        <Value>
          <![CDATA[
             select * from Articles where ID={ID}
          ]]>
        </Value>
 ..... All my queries here
</Queries>

Where do you think is the best place to put this xml file that will be deserialized for use? I think that could be good to have it into Portal.DataAccess as an embedded resource but my issue is that i dont want to access to disk everytime i want to do a query. In addition, this project doesnt contains references to WebContext (so i cannot put this in cache). For this reason i was thinking to put this file on Portal.Web which is a project with common funcionality for all websites.

What's your recomendation? Is there any other place (apart from web cache) to put the deserialized class of the xml?

Ryan Kohn
  • 13,079
  • 14
  • 56
  • 81
Jose3d
  • 9,149
  • 6
  • 33
  • 54
  • 1
    Do you mean that other projects than the DAL is performing queries? If yes, I think you going the wrong way. The dal should contains all data access logic. Higher layers should only call meaningful data access methods. Whatever the implementation is. – Steve B Aug 24 '12 at 15:20
  • The only project that does real queries (sqlconnection, etc...) is the Data Access proyect. And the Portal.Business is the proxy between front end and data access. – Jose3d Aug 24 '12 at 16:01
  • In this case none projects except DAL should now anything about your queries, and you answered yourself to your question. – vittore Aug 25 '12 at 06:15

2 Answers2

1

I think the best place will be dataacess project. Also, you could add this file to all other projects not directly, but using "add as link" option. It will allow you to change stuff only in one place and all the changes will automatically done in all 'related' files.

Also, if you want to have this queries inmemory during you app working, than it could be reasonable to put file to the root of directory and implement simple static class, which will be read this queries when applcation start and then using this class to read queries you need from memory.

Community
  • 1
  • 1
Ph0en1x
  • 9,943
  • 8
  • 48
  • 97
  • Thanks, i think is more correct if the file is on Portal.DataAccess project bus since i want to have the queries in memory and i guess i dont have another option that place it on the Portal.Web project. Regards. – Jose3d Aug 24 '12 at 16:12
0

First of all, what is the benefits of using an xml file to store queries? Most of time, queries are static and changes when the code change (new feature, bug fix, etc.).

That said, why don't you simply write the query in the code, either direclty in the consuming methods or in a dedicated const class (in the DataAccess project):

public sealed class Queries
{
    public const string Query1 = "SELECT ...";
    public const string Query2 = "SELECT ...";
}

Alternatively, you can attach the xml as a resource file and read it directly (instead of reading it from the disk).

If reading from a file is actually needed, you can perform deserialization operation once:

public class Query
{
    public string Name { get; set;}
    public string Body { get; set;}
}

public static class QueryProvider
{
    private static readonly Dictionnary<string, Query> m_Queries;

    static QueryProvider()
    {
        m_Queries = ReadTheFile(); // A method that read the files and build the dictionnary
    }

    public static Dictionnary<string, Query> Queries{ get; set;}
}

Finally, if putting the file in cache in order to be able to read it at periodic interval, you can use some IOC pattern to provide a cache provider to the underlying layers.

Steve B
  • 36,818
  • 21
  • 101
  • 174
  • I prefer in a xml file to dont have to compile the project if i change any. Thxs. Regards. Jose – Jose3d Aug 28 '12 at 14:18