开发者

Application Architecture, The best way to accomplish this

For the last two to three months iv'e been dipping and diving in and out C# and WinForms but recently I will be starting a project that will help be learn more about real life issues when programming in .NET

I'm Mainly a web based programmer working with PHP, MySql, Unix, etc and when I create a website I like to have a concrete framework that would deal with things such as:

  • Error Handling
  • Input / Output
  • Libraries
  • Application Structure
  • Database / Model abstraction
  • Resource monitoring

There's a few more to go in that list but ill keep it short.

So when im in C# I realise that when the application loads we run directly run the main form, which to me, makes you force logic for windows / forms within the Main Form/

Personally I might be wrong, and this is how it should be done, but I really do not think so, I wish to make a set of classes that control the the "Application Process" as such, this base system would control the instantiation and disposing of forms, Threading etc.

So when Application.run() fires up my application I want it to start an object called System and this object then would Parse Settings Files, Registry keys, Meta Information (CPU,Ram etc), Debugger, Switch Detection etc.

Then it would process the information and depending on the different entities effecting the application load we would run a form passing information to that form.

Within that form, If the A user clicks File > Options Then it would Ask the system to load the Options Form, , The System class would then load the Options Form passing in required information.

If that form needs to de t开发者_高级运维hread it would as the System Base if it can place it within a new thread for me, And monitor it until its complete.

What would be a good example of building a system that works like this, and do you guys have any advice on how I should go about it.

Also any really good examples,books,articles of building an MVC architecture within the C# language would also be a plus.

Please enlighten me on this subject.


Robert,

if you build a new Windows App using Visual Studio you will definitely get the main form as the first screen shown, but it does not need to be like this.

Visual Studio does this for you. It creates a Program class (Program.cs) with the Main method (which is the entry point for you application, pretty much like any other language) and call the main form for you.

Look for Program.cs and you will find this:

static class Program
{
    /// 
    /// The main entry point for the application.
    /// 
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

Knowing this you can change it and do pretty much whatever you want to change the way forms are handled by your app.


There are different architectures to meet such kind of an approach:

Layered architecture: Keep you application in layers. Implement the user interface (called presentation) in a separate layer (read assembly/executable). So the application process is now away from the winform. Keep the business logic (how the application process works) in a separate layer and the data access in a separate layer.

You can use MVC or do everything of your own. And keep the layers in the same process (in-process) by keeping them in DLLs and instantiating them in your presentation layer (the same way you are thinking as of now. So you can implement your classes in the business logic layer. The other way of thinking is the Service oriented architecture. In this case, you can run the rest of the layers as a service and consume the service(s) in the presentation layer. In that case, you can keep a single copy of the server and multiple front-end (presentation layer) application using the same.


If you are building a larger application you could build a framework to handle startup of modules, components, resources and forms, and then at the end display your form. I do this myself with MEF, so when my applications starts up, I let MEF compose all the components, retrieve my main form from MEF and then start it with Application.Run. Or I've sometimes retrived my main form controller (MVC) and told the controller to handle the Application.Run.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜