ControllerBase Anyone?

Posts   
 
    
MarcoP avatar
MarcoP
User
Posts: 270
Joined: 29-Sep-2004
# Posted on: 30-Oct-2004 01:34:10   

I'm using the adatper pattern and custom controller classes to house my business logic and data access. I remember reading a few posts on the forums and seeing others using the same pattern. I was just wondering if anyone has implemented some type of ControllerBase class? I am not far enough along with LLBL to feel really confident in my base class design. Just wondering if anyone else has thought about this.

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 01-Nov-2004 15:19:23   

Sorry for the long post, but I have included a sample ControllerClass that I use in one of my applications. The code was generated originally using the CodeSmith Templates provided by Bert, and is available in the 3rd party section.

The class basically contains all CRUD operations that I might need to use, with respect to a given entity. After I code gen the classes, I add any additional functions that I might run across throughout the development cycle.


using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Caching;

using ELogic.Framework.HelperClasses;
using ELogic.Framework.DatabaseSpecific;
using ELogic.Framework.FactoryClasses;
using ELogic.Framework.EntityClasses;
using ELogic.Framework.TypedViewClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;


namespace ELogic.Framework.ControllerClasses
{
    /// <summary>
    /// Summary description for OrganizationController.
    /// </summary>
    public class OrganizationController
    {
        public const string OrganizationCollectionCacheKey = "OrganizationCollectionCacheKey";
    
        /// <summary>
        /// private CTor so no instance can not be created.
        /// </summary>
        private OrganizationController()
        {
        }
        
        /// <summary>
        /// Returns the connection string specified in the config settings
        /// </summary>      
        public static string ConnectionString 
        {
            get
            {
                return ConfigurationSettings.AppSettings["ELogicCore.ConnectionString"];
            }
        }

        /// <summary>
        /// Returns the default sort expression for the OrganizationEntity
        /// </summary>
        public static SortExpression DefaultOrganizationSorter
        {
            get
            {
                return new SortExpression(SortClauseFactory.Create(OrganizationFieldIndex.OrganizationId, SortOperator.Ascending));
            }
        }

        #region TypedView Fetches
        public static CultureOrganizationGroupTypeTypedView FetchOrgGroupTypeByLevel(int levelId, int cultureId)
        {
            CultureOrganizationGroupTypeTypedView view = new CultureOrganizationGroupTypeTypedView();
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);

            RelationPredicateBucket bucket = new RelationPredicateBucket();
            bucket.PredicateExpression.Add(new PredicateExpression(PredicateFactory.CompareValue(
                CultureOrganizationGroupTypeFieldIndex.CultureId, ComparisonOperator.Equal,cultureId)));
            bucket.PredicateExpression.Add(new PredicateExpression(PredicateFactory.CompareValue(
                CultureOrganizationGroupTypeFieldIndex.OrganizationLevel, ComparisonOperator.Equal, levelId)));

            SortExpression sort = new SortExpression(SortClauseFactory.Create(CultureOrganizationGroupTypeFieldIndex.OrganizationGroupTypeDescr, SortOperator.Ascending));

            adapter.FetchTypedView(view.GetFieldsInfo(), view, bucket, 0, sort,false);

            return view;
        }
        #endregion
                
        
        #region Cached Collection Fetches

        //  Region Added by DevilDog74 10/06/2004
        /// <summary>
        /// Fetches the Organization collection and caches the data.
        /// </summary>
        /// <param name="cache">The existing System.Web.Caching.Cache object that is being used by the caller</param>
        /// <returns>An entity collection filled with Organization objects</returns>
        public static EntityCollection FetchOrganizationCollection(System.Web.Caching.Cache cache)
        {

            EntityCollection organizationCollection = (EntityCollection)cache[OrganizationCollectionCacheKey];
            if (organizationCollection == null)
            {
                organizationCollection = FetchOrganizationCollection();
                cache.Add(OrganizationCollectionCacheKey, organizationCollection, null,Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5), CacheItemPriority.Normal, null);
            }
            return organizationCollection;
        }
        
        
        
        /// <summary>
        /// Fetches the Organization collection and caches the data.
        /// </summary>
        /// <param name="filterBucket">The filter predicate</param>
        /// <param name="maxNumberOfItemsToReturn">Total number of items to return</param>
        /// <param name="sort">The sort expression to use</param>
        /// <param name="cache">The cache object that this object will be retreived from / cached in</param>
        /// <returns>An entity collection filled with Organization objects</returns>
        public static EntityCollection FetchOrganizationCollection(IRelationPredicateBucket filterBucket, int maxNumberOfItemsToReturn, ISortExpression sort, Cache cache)
        {
            EntityCollection organizationCollection = (EntityCollection)cache[OrganizationCollectionCacheKey];
            if (organizationCollection == null)
            {
                organizationCollection = FetchOrganizationCollection(filterBucket, maxNumberOfItemsToReturn, sort);
                cache.Add(OrganizationCollectionCacheKey, organizationCollection, null,Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5), CacheItemPriority.Normal, null);
            }
            return organizationCollection;
        }
        #endregion
        
        #region Organization Entity Collection Fetches
        /// <summary>
        /// Fetches a collection of all Organization entities sorted by the default sorter.
        /// </summary>
        /// <returns>EntityCollection</returns>
        public static EntityCollection FetchOrganizationCollection()
        {
            return FetchOrganizationCollection(null,0,DefaultOrganizationSorter);
        }
        
        /// <summary>
        /// Fetches one or more Organization entities which match the filter information in the filterBucket.
        /// </summary>
        /// <param name="filterBucket">filter information for retrieving the Organization entities. If null, all Organization entities are returned.</param>
        /// <param name="maxNumberOfItemsToReturn">The maximum amount of Organization entities to return. If 0, all Organization entities matching the filter are returned</param>
        /// <returns></returns>
        public static EntityCollection FetchOrganizationCollection(IRelationPredicateBucket filterBucket,int maxNumberOfItemsToReturn)
        {
            return FetchOrganizationCollection(filterBucket,0,null);
        }
        
        /// <summary>
        /// Fetches one or more Organization entities which match the filter information in the filterBucket.
        /// </summary>
        /// <param name="filterBucket">filter information for retrieving the Organization entities. If null, all Organization entities are returned.</param>
        /// <param name="maxNumberOfItemsToReturn">The maximum amount of Organization entities to return. If 0, all Organization entities matching the filter are returned</param>
        /// <param name="sortClauses"></param>
        /// <returns></returns>
        public static EntityCollection FetchOrganizationCollection(IRelationPredicateBucket filterBucket,int maxNumberOfItemsToReturn, ISortExpression sortClauses)     
        {
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
            EntityCollection OrganizationCollection = new EntityCollection(new ELogic.Framework.FactoryClasses.OrganizationEntityFactory());
            adapter.FetchEntityCollection(OrganizationCollection,filterBucket,0,sortClauses);
            return OrganizationCollection;
        }
        
        
        /// <summary>
        /// Fetches a collection of all Organization entities filtered by its foreign key entity objects
        /// </summary>
        /// <param name="organizationGroupType">OrganizationGroupType entity to filter by </param>
        /// <returns>EntityCollection</returns>
        public static EntityCollection FetchOrganizationCollection(OrganizationGroupTypeEntity organizationGroupType)
        {
            RelationPredicateBucket bucket = new RelationPredicateBucket();
                if (organizationGroupType != null)
                {
                    bucket.PredicateExpression.Add(PredicateFactory.CompareValue(OrganizationFieldIndex.OrganizationGroupTypeId, ComparisonOperator.Equal, organizationGroupType.OrganizationGroupTypeId));
                }
            
            return FetchOrganizationCollection(bucket,0,DefaultOrganizationSorter);
        }
        
        /// <summary>
        /// Fetches a collection of all Organization entities filtered by its foreign key fields
        /// </summary>
        /// <param name="organizationGroupTypeId">organizationGroupTypeId foreign key value to filter by </param>
        /// <returns>EntityCollection</returns>
        public static EntityCollection FetchOrganizationCollection(System.Int32 organizationGroupTypeId)
        {
            RelationPredicateBucket bucket = new RelationPredicateBucket();
                if (!Null.IsNull(organizationGroupTypeId))
                {
                    bucket.PredicateExpression.Add(PredicateFactory.CompareValue(OrganizationFieldIndex.OrganizationGroupTypeId, ComparisonOperator.Equal, organizationGroupTypeId));
                }
            
            return FetchOrganizationCollection(bucket,0,DefaultOrganizationSorter);
        }
        #endregion

        #region Organization Entity Collection As DataTable Fetches
        /// <summary>
        /// Fetches a collection of all Organization entities As a DataTable sorted by the default sorter.
        /// </summary>
        /// <returns>EntityCollection</returns>
        public static DataTable FetchOrganizationCollectionAsDataTable()
        {
            return FetchOrganizationCollectionAsDataTable(null,0,DefaultOrganizationSorter);
        }
        
        /// <summary>
        /// Fetches one or more Organization entities As a DataTable which match the filter information in the filterBucket.
        /// </summary>
        /// <param name="filterBucket">filter information for retrieving the Organization entities. If null, all Organization entities are returned.</param>
        /// <param name="maxNumberOfItemsToReturn">The maximum amount of Organization entities to return. If 0, all Organization entities matching the filter are returned</param>
        /// <returns></returns>
        public static DataTable FetchOrganizationCollectionAsDataTable(IRelationPredicateBucket filterBucket,int maxNumberOfItemsToReturn)
        {
            return FetchOrganizationCollectionAsDataTable(filterBucket,0,null);
        }
        
        /// <summary>
        /// Fetches one or more Organization entities As a DataTable which match the filter information in the filterBucket.
        /// </summary>
        /// <param name="filterBucket">filter information for retrieving the Organization entities. If null, all Organization entities are returned.</param>
        /// <param name="maxNumberOfItemsToReturn">The maximum amount of Organization entities to return. If 0, all Organization entities matching the filter are returned</param>
        /// <param name="sortClauses"></param>
        /// <returns></returns>
        public static DataTable FetchOrganizationCollectionAsDataTable(IRelationPredicateBucket filterBucket,int maxNumberOfItemsToReturn, ISortExpression sortClauses)     
        {
            OrganizationEntity organization = new OrganizationEntity();
            DataTable organizationdatatable = new DataTable();
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
            adapter.FetchTypedList(organization.Fields, organizationdatatable,filterBucket,maxNumberOfItemsToReturn,sortClauses,true);
            return organizationdatatable;
        }
        
        
        /// <summary>
        /// Fetches a collection of all Organization entities As a DataTable filtered by its foreign key entity objects
        /// </summary>
        /// <param name="organizationGroupType">OrganizationGroupType entity to filter by </param>
        /// <returns>EntityCollection</returns>
        public static DataTable FetchOrganizationCollectionAsDataTable(OrganizationGroupTypeEntity organizationGroupType)
        {
            RelationPredicateBucket bucket = new RelationPredicateBucket();
                if (organizationGroupType != null)
                {
                    bucket.PredicateExpression.Add(PredicateFactory.CompareValue(OrganizationFieldIndex.OrganizationGroupTypeId, ComparisonOperator.Equal, organizationGroupType.OrganizationGroupTypeId));
                }
            
            return FetchOrganizationCollectionAsDataTable(bucket,0,DefaultOrganizationSorter);
        }
        
        /// <summary>
        /// Fetches a collection of all Organization entities As a DataTable filtered by its foreign key fields
        /// </summary>
        /// <param name="organizationGroupTypeId">organizationGroupTypeId foreign key value to filter by </param>
        /// <returns>EntityCollection</returns>
        public static DataTable FetchOrganizationCollectionAsDataTable(System.Int32 organizationGroupTypeId)
        {
            RelationPredicateBucket bucket = new RelationPredicateBucket();
                if (!Null.IsNull(organizationGroupTypeId))
                {
                    bucket.PredicateExpression.Add(PredicateFactory.CompareValue(OrganizationFieldIndex.OrganizationGroupTypeId, ComparisonOperator.Equal, organizationGroupTypeId));
                }
            
            return FetchOrganizationCollectionAsDataTable(bucket,0,DefaultOrganizationSorter);
        }
        #endregion
        
        #region Organization Entity  Fetches
        /// <summary>
        /// Fetches an Organization entity from the persistent storage using a primary key filter. 
        /// </summary>
        /// <returns>Organization entity</returns>
        public static OrganizationEntity FetchOrganizationEntity(System.Int32 organizationId)
        {
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
            OrganizationEntity organization = new OrganizationEntity(organizationId);
            adapter.FetchEntity(organization);
            return organization;
        }
        
        /// <summary>
        /// Fetches an Territories entity from the persistent storage. 
        /// </summary>
        /// <returns>Territories entity</returns>
        public static bool FetchOrganizationEntity(OrganizationEntity organization)
        {
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
            return adapter.FetchEntity(organization);
        }

        #endregion
        
        #region OneToMany 
        #endregion
    
        #region ManyToOne
    
        /// <summary>
        /// ManyToOne
        /// Returns one instance of the entity 'OrganizationGroupType' which are directly related to the instance of the entity 'Organization' where Organization.OrganizationGroupTypeId=OrganizationGroupType.OrganizationGroupTypeId
        /// </summary>
        /// <returns></returns>
        public static OrganizationGroupTypeEntity FetchOrganizationGroupTypeEntity(OrganizationEntity organization)
        {
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
            organization.OrganizationGroupType = (OrganizationGroupTypeEntity) adapter.FetchNewEntity(new OrganizationGroupTypeEntityFactory(), organization.GetRelationInfoOrganizationGroupType());
            return organization.OrganizationGroupType;
        }
        
        /// <summary>
        /// ManyToOne
        /// Returns one instance of the entity 'OrganizationGroupType' which are directly related to the instance of the entity 'Organization' where Organization.OrganizationGroupTypeId=OrganizationGroupType.OrganizationGroupTypeId
        /// </summary>
        /// <returns></returns>
        public static OrganizationGroupTypeEntity FetchOrganizationGroupTypeEntity(System.Int32 organizationGroupTypeId)
        {
                DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
                OrganizationGroupTypeEntity OrganizationGroupType = new OrganizationGroupTypeEntity(organizationGroupTypeId);
                
                adapter.FetchEntity(OrganizationGroupType);
    
                return OrganizationGroupType;
        }
        #endregion
    
        #region ManyToMany
    
        #endregion
        
        #region Insert, Save, and Delete Entity Expiring Cache
        /// <summary>
        /// Inserts or Updates the Organization
        /// </summary>
        /// <param name="organization">The Organization that you are creating or updating</param>
        /// <param name="cache">The cache object that contains cached items</param>
        /// <returns>A boolean value indicating success or failure</returns>
        public static bool SaveOrganizationEntity(OrganizationEntity organization, Cache cache)
        {
            if (cache != null)
            {
                ScrubCache(OrganizationCollectionCacheKey, cache);
            }

            return SaveOrganizationEntity(organization);
        }

        /// <summary>
        /// Inserts or Updates a OrganizationEntity
        /// </summary>
        /// <param name="organization">The Organization entity that you are inserting / updating</param>
        /// <param name="refetchAfterSave">A boolean value that tells LLBLGen to refetch/refresh the data after the save operation</param>
        /// <param name="cache">The cache object that contains cached items</param>
        /// <returns>A boolean value indicating success or failure</returns>
        public static bool SaveOrganizationEntity(OrganizationEntity organization, bool refetchAfterSave, Cache cache)
        {
            if (cache != null)
            {
                ScrubCache(OrganizationCollectionCacheKey, cache);
            }
            return SaveOrganizationEntity(organization, refetchAfterSave);
        }

        /// <summary>
        /// Deletes a Organization using an existing entity
        /// </summary>
        /// <param name="organization">The Organization entity that you want to delete</param>
        /// <param name="cache">The object that contains cached items</param>
        /// <returns>A boolean value indicating success or failure</returns>
        public static bool DeleteOrganizationEntity(OrganizationEntity organization, Cache cache)
        {
            if (cache != null)
            {
                ScrubCache(OrganizationCollectionCacheKey, cache);
            }

            return DeleteOrganizationEntity(organization);
        }

        /// <summary>
        /// Deletes a Organization entity using the primary key of the entity
        /// </summary>
        /// <param name="organizationId">Primary key of the entity to delete</param>
        /// <param name="cache">The object that contains cached items</param>
        /// <returns>A boolean value indicating success or failure</returns>
        public static bool DeleteOrganizationEntity(System.Int32 organizationId, Cache cache)
        {
            if (cache != null)
            {
                ScrubCache(OrganizationCollectionCacheKey, cache);
            }
            return DeleteOrganizationEntity(organizationId);
        }       
        #endregion
    
        #region Insert, Save Delete Organization
        /// <summary>
        /// Creates a new OrganizationEntity
        /// </summary>
        /// <param name="portalId"></param>
        /// <param name="parentOrganizationId"></param>
        /// <param name="organizationLevel"></param>
        /// <param name="registrationMaximum"></param>
        /// <param name="totalRegistration"></param>
        /// <param name="accessCode"></param>
        /// <param name="isActive"></param>
        /// <param name="isPayPerUse"></param>
        /// <param name="organizationGroupTypeId"></param>
        public static bool InsertOrganizationEntity(System.Int32 portalId, System.Int32 parentOrganizationId, System.Int16 organizationLevel, System.Int32 registrationMaximum, System.Int32 totalRegistration, System.String accessCode, System.Boolean isActive, System.Boolean isPayPerUse, System.Int32 organizationGroupTypeId)
        {
            OrganizationEntity newOrganization = new OrganizationEntity();
            
            if (!Null.IsNull(portalId))
            {
                newOrganization.PortalId = portalId;
            }
            if (!Null.IsNull(parentOrganizationId))
            {
                newOrganization.ParentOrganizationId = parentOrganizationId;
            }
            if (!Null.IsNull(organizationLevel))
            {
                newOrganization.OrganizationLevel = organizationLevel;
            }
            if (!Null.IsNull(registrationMaximum))
            {
                newOrganization.RegistrationMaximum = registrationMaximum;
            }
            if (!Null.IsNull(totalRegistration))
            {
                newOrganization.TotalRegistration = totalRegistration;
            }
            if (!Null.IsNull(accessCode))
            {
                newOrganization.AccessCode = accessCode;
            }
            if (!Null.IsNull(isActive))
            {
                newOrganization.IsActive = isActive;
            }
            if (!Null.IsNull(isPayPerUse))
            {
                newOrganization.IsPayPerUse = isPayPerUse;
            }
            if (!Null.IsNull(organizationGroupTypeId))
            {
                newOrganization.OrganizationGroupTypeId = organizationGroupTypeId;
            }
            return SaveOrganizationEntity(newOrganization);
        }
        
        /// <summary>
        /// Saves the passed in Organization entity to the persistent storage. If the organization entity is new, it will be inserted, if theorganization entity is existent, the changed
        /// entity fields will be changed in the database.
        /// </summary>
        /// <param name="organization">The organization entity to save</param>
        /// <returns>true if the save was succesful, false otherwise.</returns>
        public static bool SaveOrganizationEntity(OrganizationEntity organization)
        {
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
            return adapter.SaveEntity(organization);
        }
        
        /// <summary>
        /// Saves the passed in Organization entity to the persistent storage. If the organization entity is new, it will be inserted, if the organization entity is existent, the changed
        /// entity fields will be changed in the database.
        /// </summary>
        /// <param name="organization">The organization entity to save</param>
        /// <param name="refetchAfterSave">A boolean value indicating if the entity is to be refetched after the save operation</param>
        /// <returns>true if the save was succesful, false otherwise.</returns>
        public static bool SaveOrganizationEntity(OrganizationEntity organization, bool refetchAfterSave)
        {
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
            return adapter.SaveEntity(organization, refetchAfterSave);
        }

        /// <summary>
        /// Deletes the specified organization entity from the persistent storage. The organization entity is not usable after this call, the state is set to
        /// OutOfSync.
        /// </summary>
        /// <param name="organization">The organization entity instance to delete from the persistent storage</param>
        /// <returns></returns>
        public static bool DeleteOrganizationEntity(OrganizationEntity organization)
        {
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
            return adapter.DeleteEntity(organization);
        }

        /// <summary>
        /// Deletes the specified organization entity from the persistent storage. The organization entity is not usable after this call, the state is set to
        /// OutOfSync.
        /// </summary>
        /// <param name="organizationId">The PK Value of the order Entity to delete</param>
        /// <returns>true if the delete was succesful, otherwise false.</returns>
        public static bool DeleteOrganizationEntity(System.Int32 organizationId)
        {
            OrganizationEntity organization = new OrganizationEntity(organizationId);
            return DeleteOrganizationEntity(organizationId);
        }
        
        /// <summary>
        /// Deletes all organization entities from the persistent storage if they match the filter
        /// supplied in <i>filterBucket</i>.
        /// </summary>
        /// <param name="filterBucket"></param>
        /// <returns>execution result, which is the amount of rows affected (if applicable)</returns>
        public static int DeleteOrganizationMulti(IRelationPredicateBucket filterBucket)
        {
            DataAccessAdapter adapter = new DataAccessAdapter(ConnectionString);
            return adapter.DeleteEntitiesDirectly("OrganizationEntity", filterBucket);
        }
        #endregion
    
        #region Cache Helper Members
        /// <summary>
        /// Removes any item from the passed in cache object, that has the same key as the key value 
        /// that was passed in.
        /// </summary>
        /// <param name="cacheKey">The cache key of the item to expire</param>
        /// <param name="cache">The cache object that contains cached items</param>
        public static void ScrubCache(string cacheKey, Cache cache)
        {
            if (cache[cacheKey] != null)
            {
                cache.Remove(cacheKey);
            }
        }
        #endregion
    }
}



MarcoP avatar
MarcoP
User
Posts: 270
Joined: 29-Sep-2004
# Posted on: 01-Nov-2004 19:55:27   

that's cool. here is an example of my controller base. i think in my implementation of the controller base, it is easier to share connections (keepConnectionOpen), without overloading all the methods in the controller.


Imports Sheakley.Evolution.Security
Imports Sheakley.Evolution.Configuration
Imports Microsoft.ApplicationBlocks.ExceptionManagement

Public MustInherit Class ControllerBase

    Private _dataAccessAdapter As DataAccessAdapter
    Private _configManager As ConfigurationManager = ConfigurationManager.GetConfig()
    Private _providerInfo As ProviderInfo = _configManager.DatabaseConfig.GetProviderInformation(Catalog.WC)

    Protected Overloads Function CreateDataAccessAdapter() As DataAccessAdapter
        If _dataAccessAdapter Is Nothing Then CreateDataAccessAdapter(False)
        Return _dataAccessAdapter
    End Function

    Protected Overloads Function CreateDataAccessAdapter(ByVal keepConnectionOpen As Boolean) As DataAccessAdapter
        If _dataAccessAdapter Is Nothing Then
            _dataAccessAdapter = New DataAccessAdapter(_providerInfo.ConnectionString, keepConnectionOpen, CatalogNameUsage.ForceName, _providerInfo.Catalog)
        End If
        Return _dataAccessAdapter
    End Function

    Protected Overloads Sub PublicException(ByVal ex As Exception)
        ExceptionManager.Publish(ex)
    End Sub

    Protected Overloads Sub PublicException(ByVal ex As Exception, ByVal additionalInfo As Specialized.NameValueCollection)
        ExceptionManager.Publish(ex, additionalInfo)
    End Sub

    Protected ReadOnly Property CurrentPrincipal() As SheakleyPrincipal
        Get
            Return SecurityManager.CurrentPrincipal
        End Get
    End Property

    Protected ReadOnly Property Configuration() As ConfigurationManager
        Get
            Return _configManager
        End Get
    End Property
End Class

erichar11
User
Posts: 268
Joined: 08-Dec-2003
# Posted on: 01-Nov-2004 23:53:09   

Hi Marco, DevilDog,

For us newbies, could you please explain why a controller class is needed? I just don't see the benefit and was hoping you could shed some on light on why a controller is needed. Is there a design pattern that is associated with this? Thanks for any help.

MarcoP avatar
MarcoP
User
Posts: 270
Joined: 29-Sep-2004
# Posted on: 02-Nov-2004 00:26:01   

erichar11 wrote:

Hi Marco, DevilDog,

For us newbies, could you please explain why a controller class is needed? I just don't see the benefit and was hoping you could shed some on light on why a controller is needed. Is there a design pattern that is associated with this? Thanks for any help.

Hi erichar, By implementing the controller classes in a seperate assembly, it allows for greater seperation between the tiers, as well as a central repository for storing core business logic. From a UI perspective, the user interface developers do not need to be concerned with the complexities of prefetch paths, transactions, concurrency, etc. Not only will this seperation allow other departments or applications at our company to reuse our existing framework, but will also make it much easier to scale our application out on multiple servers if the need arises.

HTH

erichar11
User
Posts: 268
Joined: 08-Dec-2003
# Posted on: 02-Nov-2004 05:29:59   

MarcoP, but can't this be achieved (seperation of tiers) without the need for a controller? For example, I have all my business logic in a seperate assembly and the pl knows nothing about llblgen. I accomplish this by passing back datatables to the ui and working with them and not passing back llblgen entities or derived entities. This is where I'm getting confused on how a controller helps.

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 02-Nov-2004 14:23:30   

With my usage, all a controller does is provide ways to perform Create, Read, Update, and Delete logic.

You technically, dont need these, you could implement this logic client side, or you could have some sort of wrapper for this functionality, like in your scenario.

Typically, my services layer comprises of Controller Classes, Helper Classes, and Custom Business Objects, like data mappers, data transfer objects, unit of work objects, or aggregate domain type objects. The UI typically works directly with a services layer or some wrapper for a services layer, i.e. a MarshalByRefObj class or an XML Web Service.

So, I think Eric, that we are actually doing the same type of thing.