Survey Forums

HomeHomeSurvey Project ...Survey Project ...DevelopmentDevelopmentDALFactory - a generic versionDALFactory - a generic version
Previous
 
Next
New Post
11/4/2010 4:31 AM
 

 Hi,

I thought I would post this suggested improvement to your DAL Factories, as it would simplify your code, while still providing the current functionality..

You've currently got 1 factory class for each DAL Interface. If you use the following class, which utilises generics, you can replace all of them with just the one class..

// DALFactory.cs
namespace Votations.NSurvey.DALFactory
{

    using System;

    using System.Collections.Specialized;

    using System.Configuration;

    using System.Reflection;

    using Votations.NSurvey.IDAL;

        

    public class DALFactory<T>

    {

        public static T Create()

        {

            NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("nSurveySettings");

            if (config == null)

            {

                config = ConfigurationManager.AppSettings;

            }

            string assemblyString = config["WebDAL"];

            string typeName = assemblyString + "."  + typeof(T).Name.ToString().Substring(1);

            return (T)Assembly.Load(assemblyString).CreateInstance(typeName);

        }

    }

}

 
This class could then be called from any of the BusinessRules or DataAccess classes as follows..
 
DALFactory< *YOUR INTERFACE *>.Create(). * FUNCTION CALL *
eg..
DALFactory<IVoter>.Create().DeleteVoterResumeSession(surveyId, resumeUId);
 
Hope this helps..
grakenmol..
 
New Post
11/5/2010 1:27 PM
 

Hi,

Thank you very much for your contribution, it's greatly appreciated. We will add the suggested code to the issue tracker at http:/survey.codeplex.com and try to implement this on the next Survey version.

If you have any other contributions of suggested improvements please let us know. Also if you're interested you could apply for the projectteam at codeplex.com. We're still looking for people with different kinds of skills to make the Survey project a success.


 

 
Previous
 
Next
HomeHomeSurvey Project ...Survey Project ...DevelopmentDevelopmentDALFactory - a generic versionDALFactory - a generic version