Windows Forms Application Creation and Initialization

This topic details the steps performed after an end-user has run an XAF Windows Forms application, until the moment the main XAF objects, like the WinApplication, are created and initialized.

In the following image, you can see that the entire process of application creation and initialization can be divided into four steps.

The table below describes all these steps in detail.

Stage Description Ways to Interfere
Create an Application An instance of the WinApplication is created. This is performed by the Program.Main method, automatically generated in your Windows Forms application project.  
Initial Application Initialization A newly created application is initialized. The settings that are specified in the configuration file's appSettings section are read to the application:  
 

The XafApplication.TablePrefixes property is set to the value assigned to the TablePrefixes key in the configuration file.

If it is not necessary for you to set table prefixes in the configuration file, you can do it in code. To do this, set the TablePrefixes property after an application object has been created, but before its XafApplication.Setup method is called.
 

The location to be used to store the Model.User.xafml file is specified by the UserModelDiffsLocation key.

 
 

The location to be used to store the application's Log file is specified by the TraceLogLocation key.

 
Application Initialization by the Designer Then, the application is initialized by the values specified in the Application Designer. This is performed by the InitializeComponent method, automatically called in the constructor of your WinApplication class.  
 

The XafApplication.Modules collection is populated by the modules added to the Modules section in the Designer. Each module is set up. This means that the current WinApplication instance is assigned to the ModuleBase.Applicationproperty.

If you need to add a module that is not registered in the Toolbox, and so cannot be added via the Designer, use one of the following approaches:

Specify the required module name(s) in the application project's configuration file. Pass this string as a parameter of the XafApplication.Setupmethod in the Program.Main method.

Add this module to the module that is contained in your solution. To do this, use the ModuleBase.RequiredModuleTypes collection.

To see code samples of both these approaches, refer to the Ways to Register a Module topic.

You can perform custom actions with a module, in addition to setting the Application object. To do this, override the module's ModuleBase.Setup method.

 

The XafApplication.Connection property is set to the object of the type specified in the Designer's Connection section. The connection string is specified in the Properties grid when the Connection section is selected.

You can avoid the use of the Designer by applying one of the following techniques:

Specify the connection string in the application project's configuration file. Assign this string to the XafApplication.ConnectionString property (see this property's description).

Set the XafApplication.Connection and/or XafApplication.ConnectionString property before the XafApplication.Setup method is called.

 

The XafApplication.Security property is set to the object of the type specified in the Designer's Security section. The authentication strategy to be used by the Security System is specified in the same section. The User type to be used by the Security System is specified in the Properties grid when the Security section is selected.

The eXpressApp Framework supplies two security system types: SecuritySimple and SecurityComplex. You can set them using the Application Designer. If you need to use a custom security type that implements the ISecurity interface, create and assign it to the XafApplication.Security property in code, before the XafApplication.Setup method is called. If you need to use a custom authentication strategy or a custom User type, initialize them and the XafApplication.Security property, before the XafApplication.Setup method is invoked.

If you do not initialize a security system via the Application Designer or in code, a SecurityDummy will be used. This security type allows all operations with all types of objects. That's why the presence of the security system is invisible when you run an application.

 

The XafApplication.ApplicationName property is set to the value that is specified in the Properties grid when the Application section is selected.

You can assign a custom value to the XafApplication.ApplicationName property in code - before the XafApplication.Setup method is called.
Application Initialization by the Setupmethod The XafApplication.Setup method is called. This is performed by the Program.Mainmethod that is automatically generated in your Windows Forms application project.
There are several overloads of the Setup method. By default, the method without parameters is called. It leaves the properties that are already initialized as they are, and proceeds with the initialization process using default values:
You can call the Setup method with the required parameters, depending on what custom objects you need to create. However, we recommend that you use the approaches presented above, instead.
 

A default splash screen form (DevExpress.ExpressApp.Win.Core.SplashScreen) is shown.

You can set a custom splash screen using the WinApplication.SplashScreen property. The custom splash screen must implement the ISplashinterface. To see an example, refer to the How to: Use a Custom Splash Screen topic.
 

A default Object Space Provider (see XafApplication.ObjectSpaceProvider) is created using the connection string specified by the XafApplication.ConnectionStringproperty.

To create a custom Object Space Provider subscribe to the XafApplication.CreateCustomObjectSpaceProvider event, before the Setup method is called. Alternatively, pass the required ObjectSpaceProvider object, using the Setup method as a parameter.
You can override the XAFApplication.CreateDefaultObjectSpaceProvider method in your WinApplication class descendant. This method is called when no custom approaches to pass an Object Space Provider are used. This method creates an instance of the built-in ObjectSpaceProvider class. You can return an instance of another class that implements the IObjectSpaceProvider interface.
 

A default Controllers Manager (ControllersManager) is created. This object contains a collection of all the Controllers that are declared in the registered modules.

You can override the XAFApplication.CreateControllersManager method in your WinApplication class descendant. This method creates an instance of the built-in ControllersManager class. You can return an instance of another class.
 

A default Modules Manager (ApplicationModulesManager) is created. This object contains the Modules collection with the modules to be used by the application. This collection is populated by the modules from the XafApplication.Modulescollection. In addition, the SystemModule is added as a default module.

You can override the XAFApplication.GetDefaultModuleTypes method in your WinApplication class descendant. This method creates an instance of the built-in ApplicationModulesManager class. You can return an instance of another class.
In addition, you can override the GetDefaultModuleTypes method to return modules to be added to the application by default, in addition to the System module.
 

A default Application Model Differences Store (FileModelStore) is created.

If you need to store an Application Model's differences in a place that is different from an XafML file, you can create a custom Application Model Differences Store. To do this, subscribe to the XafApplication.CreateCustomModelDifferenceStore event before the Setup method is called, or override the WinApplication.CreateModelDifferenceStoreCore method in your WinApplication class descendant.
 

The Object Space Provider and Controllers Manager are assigned to the application's corresponding properties: XafApplication.ObjectSpaceProvider and ControllersManager.

Subscribe to the XafApplication.SettingUp event, to customize the objects to be assigned to the application object. Use the event handler's parameters to access the required objects.
 

The modules from the Modules Manager's Modules collection are added to the XafApplication.Modules collection of the current application, since at this step the latter collection includes the modules that are only added via the Application Designer.

 
 

The Application Model Manager (ApplicationModelsManager) which manages the creation and initialization of the Application Model is instantiated.

 
 

The Application Model is created. Internally, the Application Model has a layered structure, so at first, the actual layers that comprise the Application Model internals are created:

 
 

The zero layer of the Application Model is created. Initially, it is empty. It is filled with data on demand, during the application life cycle.

To extend the Application Model, pass the required model interfaces via the application modules' ModuleBase.ExtendModelInterfacesmethods. Alternatively, you can implement the IModelExtender interface in Controllers. To modify existing node generators, implement a generator updater and register it via the ModuleBase.AddGeneratorUpdaters method of a module. For details, refer to the Extend and Customize the Application Model in Code topic.
 

A layer for each module used in the application is created. This layer is filled with data from the Model.DesignedDiffs.xafml file that contains Application Model differences created in a particular module.

To modify this layer's data, modify the required module's XafML file. This can be done, for example, via the Model Editor.
 

A layer for the application project is created. This layer is filled with data from the Model.xafml file that contains Application Model differences created in the application project.

To modify this layer's data, modify the application project's XafML file. This can be done, for example, via the Model Editor.
 

Second, all the created layers are wrapped with the master layer.

The master layer does not contain any information itself. It serves as a proxy for all other layers. Usually, when you access the Application Model, you deal with the master layer.
 

The final state of the Application Model is assigned to the XafApplication.Modelproperty.

Subscribe to the XafApplication.SetupComplete event to create extra objects (helpers, extractors, etc.), after the application has been completely initialized.

Windows Forms Application Creation and Initialization的更多相关文章

  1. create Context Menu in Windows Forms application using C# z

    In this article let us see how to create Context Menu in Windows Forms application using C# Introduc ...

  2. Catch Application Exceptions in a Windows Forms Application

    You need to handle the System.Windows.Forms.Application.ThreadException event for Windows Forms. Thi ...

  3. 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别

    原文:[C#遗补]获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPa ...

  4. System.Windows.Forms.Application.DoEvents();

    关于Application.DoEvents()的小研究 在MSDN中的备注是: 当运行 Windows 窗体时,它将创建新窗体,然后该窗体等待处理事件.该窗体在每次处理事件时,均将处理与该事件关联的 ...

  5. Windows Forms (一)

    导读 1.什么是 Windows Forms 2.需要学Windows Forms 么? 3.如何手写一个简单的Windows Forms 程序 4.对上面程序的说明 5.Form 类与Control ...

  6. 如何为Windows Forms应用程序添加启动参数(Start-Up Parameters)

    很多场合下,我们需要通过命令行或者快捷方式在Windows Forms程序启动时向其传递参数. 这些参数可能是用来加载某一个文档,或者是应用程序的初始化配置文件. 特别是对那些需要高度自定义配置的大程 ...

  7. 体验Visual Studio 2015 Windows Forms应用程序开发与维护

    昨天到半夜还没有等到Visual Studio 2015的下载地址,实在熬不住就先休息了.北美地区的时区比北京时间要晚一些,今天早上到公司就看到Visual Studio 2015的下载地址,迅速的将 ...

  8. Double Buffering Windows Forms

    Double Buffering Windows Forms As much as we would like it not to be the case, graphics can be slow ...

  9. C# Windows Forms 事件处理顺序

    事件引发的顺序对某些Windows 窗体应用来说十分重要.当某些事件需要特别处理时(如重绘窗体的某些部分),必须知道事件在运行时的确切引发顺序.下面就应用程序和控件的生命周期中的几个重要阶段的事件顺序 ...

随机推荐

  1. Java通过Shell执行Sqoop命令没日志的问题

    修改执行部分的代码,改成用InputStream.read(byte[])的方法从流中读取数据 package com.example.demo.utils; import java.io.*; pu ...

  2. 微信小程序websocket

    微信小程序websocket 微信小程序带有websocket可以提供使用,但是官方文档写的东西很少,而且小程序后台能力弱这一点也是十分的坑爹,这就导致了socket长连接一切后台就会出现断开的情况, ...

  3. 长距离单历元非差GNSS网络RTK理论与方法总结(未完)

    2018-11-04 1.状态空间: 状态空间是控制工程中的一个名词.状态是指在系统中可决定系统状态.最小数目变量的有序集合.   而所谓状态空间则是指该系统全部可能状态的集合.简单来说,状态空间可以 ...

  4. Java重写&重载

      在学习完类和对象后,接下来就要进入面向对象的内容了,先从重写和重载开始吧.重写(Override)和重载(Overload)是两个不同的概念,也是两个容易混淆的概念,下面具体来说说这两者. 重写( ...

  5. debian 7上安装svn

    1.在终端中直接输入  sudo apt-get install subversion,选择安装即可 2.查看版本命令 svnserve --version(更多命令直接键入svnserve --he ...

  6. Tomcat6的相关配置

    1. Tomcat无安装部署: 本文windows用的是win7,ubuntu用的是12.04 LTS,tomcat版本是1.6 1.1. windows上的tomcat无安装部署 1.1.1. 确认 ...

  7. 51 nod 1682 中位数计数

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1682 1682 中位数计数 基准时间限制:1 秒 空间限制: ...

  8. Linux配置CentOs7.4(网络连接处理)

    说明:CentOS 7.0默认安装好之后是没有自动开启网络连接的! 进入登录界面 账号输入root 回车 再输入上面设置的root密码回车 系统登录成功 设置IP地址.网关DNS cd  /etc/s ...

  9. 1066. [SCOI2007]蜥蜴【最大流】

    Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃 到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到 ...

  10. Word中摘要和正文同时分栏后,正文跑到下一页,怎么办?或Word分栏后第一页明明有空位后面的文字却自动跳到第二页了,怎么办?

    问题1:Word中摘要和正文同时分栏后,正文跑到下一页,怎么办?或Word分栏后第一页明明有空位后面的文字却自动跳到第二页了,怎么办? 答:在word2010中,菜单栏中最左侧选“文件”->“选 ...