Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Building an MVP Framework for .NET. Part 2: Implementing Core Functionality

, 11 Feb 2008
Basing on the concepts introduced in the first part, this article proceeds to implement the core MVP Framework funtionality.
mvcsharp.zip
MVCSharp
API Docs
CleanUpAll.proj
Examples
Basics
ApplicationLogic
Model
Presentation
Web
Global.asax
Win
Properties
Settings.settings
SimpleFormsViewsManager
Properties
TestSimpleFormsViewsManager
ApplicationLogic
Presentation
Properties
Settings.settings
TasksInteraction
ApplicationLogic
Model
Presentation
Web
Global.asax
Win
Properties
Settings.settings
WindowsFormsExample
ApplicationLogic
Presentation
Properties
Settings.settings
MVCSharp
Core
Configuration
Tasks
Views
Tasks
Views
Properties
Webforms
Configuration
Winforms
Configuration
MVCSharp.Tests
Core
Configuration
Tasks
Views
Tasks
MVCSharp.Tests.csproj.user
Properties
Webforms
Configuration
Winforms
Configuration
//===========================================
// MVC# Framework | www.MVCSharp.org        |
// ------------------------------------------
// Copyright (C) 2008 www.MVCSharp.org      |
// All rights reserved.                     |
//===========================================

using System;
using System.Text;
using System.Reflection;
using MVCSharp.Core.Configuration.Views;
using MVCSharp.Core.Configuration.Tasks;

namespace MVCSharp.Core.Configuration
{
    #region Documentation
    /// <summary>
    /// Represents configuration data for an MVC# application. It
    /// contains descriptions for all tasks and views (
    /// <see cref="MVCConfiguration.TaskInfos"/> and <see cref="MVCConfiguration.ViewInfosByTask"/>
    /// properties) and other configuration data.
    /// </summary>
    /// <remarks>Every <see cref="MVCSharp.Core.Tasks.TasksManager"/> instance has its
    /// own MVCConfiguration object and starts tasks accordingly
    /// to this configuration.
    /// </remarks>
    #endregion
    public class MVCConfiguration
    {
        private Type viewInfosProviderType;
        private Type taskInfoProviderType;
        private Type viewsManagerType;
        private Assembly viewsAssembly;
        private ViewInfosByTaskCollection viewInfosByTask;
        private ITaskInfoProvider taskInfoProvider;
        private TaskInfoCollection taskInfos;

        #region Documentation
        /// <summary>
        /// Parameterless constructor.
        /// </summary>
        #endregion
        public MVCConfiguration()
        {
            TaskInfos = new TaskInfoCollection();;
            TaskInfos.MVCConfig = this;
        }

        #region Documentation
        /// <summary>
        /// Returns the default MVCConfiguration instance with
        /// <see cref="MVCConfiguration.ViewInfosProviderType"/> set to <see cref="DefaultViewInfosProvider"/>
        /// and <see cref="MVCConfiguration.TaskInfoProviderType"/> set to <see cref="DefaultTaskInfoProvider"/>
        /// and <see cref="MVCConfiguration.ViewsAssembly"/> pointing to the calling assembly.
        /// </summary>
        #endregion
        public static MVCConfiguration GetDefault()
        {
            MVCConfiguration result = new MVCConfiguration();
            result.viewInfosProviderType = typeof(DefaultViewInfosProvider);
            result.taskInfoProviderType = typeof(DefaultTaskInfoProvider);
            result.ViewsAssembly = Assembly.GetCallingAssembly();
            return result;
        }

        #region Documentation
        /// <summary>
        /// Specifies the type of the <see cref="IViewInfosProvider"/> implementation
        /// used to populate view descriptions (
        /// <see cref="MVCConfiguration.ViewInfosByTask"/> property).
        /// </summary>
        #endregion
        public Type ViewInfosProviderType
        {
            get { return viewInfosProviderType; }
            set { viewInfosProviderType = value; }
        }

        #region Documentation
        /// <summary>
        /// Specifies the type of the <see cref="ITaskInfoProvider"/> implementation
        /// used to populate task descriptions (
        /// <see cref="MVCConfiguration.TaskInfos">MVCConfiguration.TaskInfos</see> property).
        /// </summary>
        #endregion
        public Type TaskInfoProviderType
        {
            get { return taskInfoProviderType; }
            set { taskInfoProviderType = value; }
        }

        #region Documentation
        /// <summary>
        /// Specifies a views manager type (<see cref="MVCSharp.Core.Views.IViewsManager"/> implementation)
        /// to be used.
        /// </summary>
        #endregion
        public Type ViewsManagerType
        {
            get { return viewsManagerType; }
            set { viewsManagerType = value; }
        }

        #region Documentation
        /// <summary>
        /// Gets or sets an assembly containing view descriptions. These
        /// descriptions are converted by the <see cref="MVCConfiguration.ViewInfosProviderType"/> class
        /// to <see cref="ViewInfo"/> objects and stored in <see cref="MVCConfiguration.ViewInfosByTask">
        /// MVCConfiguration.ViewInfosByTask</see> collections.</summary>
        #endregion
        public Assembly ViewsAssembly
        {
            get { return viewsAssembly; }
            set { viewsAssembly = value; }
        }

        #region Documentation
        /// <summary>
        /// Gets a set of <see cref="ViewInfoCollection"/> objects for
        /// every task. These objects are produced by an instance of the
        /// <see cref="MVCConfiguration.ViewInfosProviderType">
        /// MVCConfiguration.ViewInfosProviderType</see> type</summary>
        #endregion
        public ViewInfosByTaskCollection ViewInfosByTask
        {
            get
            {
                if (viewInfosByTask == null)
                {
                    IViewInfosProvider viewInfosProvider = CreateHelper.Create(
                                        ViewInfosProviderType) as IViewInfosProvider;
                    viewInfosByTask = viewInfosProvider.GetFromAssembly(ViewsAssembly);
                }
                return viewInfosByTask;
            }
        }

        #region Documentation
        /// <summary>
        /// Gets or sets an associated <see cref="ITaskInfoProvider"/> instance used
        /// to convert task types to <see cref="TaskInfo"/> objects.
        /// </summary>
        #endregion
        public ITaskInfoProvider TaskInfoProvider
        {
            get
            {
                if (taskInfoProvider == null)
                    taskInfoProvider = CreateHelper.Create(TaskInfoProviderType)
                                                            as ITaskInfoProvider;
                return taskInfoProvider;
            }
            set
            {
                taskInfoProvider = value;
            }
        }

        #region Documentation
        /// <summary>
        /// Associates MVCConfiguration to task descriptions.
        /// </summary>
        #endregion
        public TaskInfoCollection TaskInfos
        {
            get { return taskInfos; }
            set { taskInfos = value; }
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Oleg Zhukov
Team Leader
Russian Federation Russian Federation
Oleg Zhukov, born and living in Russia is Lead Engineer and Project Manager in a company which provides business software solutions. He has graduated from Moscow Institute of Physics and Technology (MIPT) (department of system programming) and has got a M.S. degree in applied physics and mathematics. His research and development work concerns architectural patterns, domain-driven development and systems analysis. Being the adherent of agile methods he applies them extensively in the projects managed by him.

| Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 11 Feb 2008
Article Copyright 2008 by Oleg Zhukov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid