This project has moved. For the latest updates, please go here.

 

Quickest Start

The quickest way to get started is using one of the existing samples in the sample directory

 

Less Quick start

If you would like to add the AppCan changes yourself it is possible, the second way is to start from a prism app like Hello World and add AppCan Manually.

 

Start with the basic Hello World prism application. 

 

Add references to the two main libraries:

AppCan.Core

AppCan.wpf

 Can also add the external log4net logging library (optional)

 

Derive the application class from the AppCanApp class:

public partial class App : AppCanApp

 

Update the App.xaml file so that it references the AppCanApp class:

<z:AppCanApp x:Class="HelloWorld.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:z="clr-namespace:AppCan.wpf.Application;assembly=AppCan.Wpf"
    xmlns:y="clr-namespace:HelloWorld;assembly=HelloWorld"
    >

    <z:AppCanApp.Resources>

    </z:AppCanApp.Resources>
</z:AppCanApp>

 

Change the shell class to derive from the interface IViewContainer:

public partial class Shell : Window, IViewContainer

 

 Change the Bootstrapper class to take a reference to the app class and should look like this:

using AppCan.Core.Contexts;
using AppCan.wpf.Application;
using AppCan.wpf.Views;
//using log4net;
//using log4net.Config;
using Microsoft.Practices.Prism.Logging;

class Bootstrapper : UnityBootstrapper
    {
        Context _context;
        Window _window;
        App _app;

        public Bootstrapper(App app)
        {
            _app = app;
       
            //Configure log4net if desired
            //XmlConfigurator.Configure(new System.IO.FileInfo("Log4net.xml"));

        }

        


        protected override DependencyObject CreateShell()
        {
            _app.CreateShell(null);

            //load configuration if desired
            _app.ContextManager.LoadConfiguration("ContextDefs.xml");
            
            _app.ContextManager.GetNewOrExistingContextDef("HelloWorld.Shell").Container.RegisterType<IViewContainer, Shell>(new ContainerControlledLifetimeManager());

            

            
            Context ct =_app.ContextManager.GetNewOrExistingContextDef("HelloWorld.Shell").GetNewContext();
            _context = ct;

            _window = (Window)ct.Container.Resolve<IViewContainer>();

            return _window;

        }

        protected override void InitializeShell()
        {
            base.InitializeShell();

            _app.InitializeShell();

            App.Current.MainWindow = (Window)this.Shell;


        }

        protected override void InitializeModules()
        {
            base.InitializeModules();
            _context.Create();

        }


        protected override void ConfigureModuleCatalog()
        {
            base.ConfigureModuleCatalog();
            _app.ConfigureModuleCatalog();

            ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
            moduleCatalog.AddModule(typeof(HelloWorldModule.HelloWorldModule));
        }

        /* If log4net is desired
        protected virtual ILoggerFacade CreateLogger()
        {
            return new Log4NetLogger();
        } */

        
        
    }
Derive your Shell class from IViewContainer:
public partial class Shell : Window, IViewContainer
Example Initialize Method for the Hello World module:
 //Get the container
            IUnityContainer container=ServiceLocator.Current.GetInstance<IUnityContainer>();
            
            //Get the context manager
            IContextManager cm = container.Resolve<IContextManager>();

            //Get the context definition
            IContextDef cd=cm.GetNewOrExistingContextDef("HelloWorld.Shell");

            //Register the view to the context definition 
            cd.Container.RegisterType<IView, HelloWorldView>();

            //Register the view model to the context definition
            cd.Container.RegisterType<IViewModel, HellowWorldViewModel>();

            //Get the context region manager from the context definition 
            IContextRegionManager crm=cd.Container.Resolve<IContextRegionManager>();
            
            //- we will pre-register that the IView that we registered we want to go to a particular region
            //When the context definition is created the regions will be created into the context
            crm.RegisterViewWithRegion<IView>("MainRegion");
Derive the Modules view from IView and if you have a view model from IViewModel:
public partial class HelloWorldView : UserControl, IView

Last edited Mar 17, 2013 at 3:15 AM by davesspacebar, version 4

Comments

No comments yet.