Ejemplo n.º 1
0
    /// <summary>
    /// Registers the routes.
    /// </summary>
    /// <param name="viewRoutes">The view routes.</param>
    /// <param name="apiRoutes">The API routes.</param>
    /// <param name="logger">The logger.</param>
    public static void RegisterRoutes(RouteCollection viewRoutes, HttpRouteCollection apiRoutes, ILogger logger)
    {

      logger.LogDebug("START: ModuleConfig.RegisterRoutes");
      try
      {
        logger.Indent();

        logger.LogDebug("GetViewModules");
        var vModules = MEFConfig.Container.GetExports<IViewModule>();
        logger.LogDebug("GetServiceModules");
        var sModules = MEFConfig.Container.GetExports<IServiceModule>();

        logger.LogDebug("Iterating ViewModules");
        logger.Indent();
        foreach (var module in vModules)
        {
          var mod = module.Value;
          mod.RegisterRoutes(viewRoutes);

          logger.LogDebug(mod.GetType().FullName);
        }
        logger.UnIndent();

        logger.LogDebug("Iterating ServiceModules");
        logger.Indent();
        foreach (var module in sModules)
        {
          var mod = module.Value;
          mod.RegisterRoutes(apiRoutes);

          logger.LogDebug(mod.GetType().FullName);
        }
        logger.UnIndent();
      }
      finally
      {
        logger.UnIndent();
        logger.LogDebug("END: ModuleConfig.RegisterRoutes");
      }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Registers the bundles.
    /// </summary>
    /// <param name="bundles">The bundles.</param>
    /// <param name="logger">The logger.</param>
    public static void RegisterBundles(BundleCollection bundles, ILogger logger)
    {
      logger.LogDebug("START: ModuleConfig.RegisterBundles");
      try
      {
        logger.Indent();
        logger.LogDebug("GetViewModules");
        var vModules = MEFConfig.Container.GetExports<IViewModule>();

        // process each module
        logger.LogDebug("Iterating ViewModules");
        logger.Indent();
        foreach (var module in vModules)
        {
          // get the non lazy module value
          var mod = module.Value; // as IViewModule;

          if (mod != null)
          {
            // add any bundles the module may need
            mod.RegisterBundles(bundles);
          }

          logger.LogDebug(mod.GetType().FullName);
        }
        logger.UnIndent();

      }
      finally
      {
        logger.UnIndent();
        logger.LogDebug("END: ModuleConfig.RegisterBundles");
      }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Initialises the modules internals.
    /// </summary>
    /// <param name="logger">The logger.</param>
    public static void InitialiseModules(ILogger logger)
    {
      logger.LogDebug("START: ModuleConfig.InitialiseModules");
      try
      {
        logger.Indent();
        logger.LogDebug("GetModules");

        var modules = MEFConfig.Container.GetExports<IServiceModule>().Select(m => (IModule)(m.Value))
                    .Union(
                        MEFConfig.Container.GetExports<IViewModule>().Select(m => (IModule)(m.Value))
                    );

        // process each module
        logger.LogDebug("Iterating Modules");
        logger.Indent();
        foreach (var module in modules)
        {
          // get the non lazy module value
          if (module != null)
          {
            module.InternalInit();
          }

          logger.LogDebug(module.GetType().FullName);
        }
        logger.UnIndent();
      }
      finally
      {
        logger.UnIndent();
        logger.LogDebug("END: ModuleConfig.InitialiseModules");
      }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Start the Application.
    /// </summary>
    protected void Application_Start()
    {
      System.Diagnostics.Trace.WriteLine("{0} :: Application Starting".FormatWith(DateTime.Now.ToString("HH:mm:ss.ff")));

      // MEF will load all the modules from the specified path.
      // Currently this is just the normal bin folder as having them
      // anywhere else can cause problems for the views
      System.Diagnostics.Trace.WriteLine("{0} ::  Initialising MEF".FormatWith(DateTime.Now.ToString("HH:mm:ss.ff")));
      MEFConfig.RegisterMEF(this, Server.MapPath(@"~\bin\"));

      _logger = MEFConfig.Container.GetExport<ILogger>().Value;
      _settings = MEFConfig.Container.GetExport<ISettings>().Value;

      // once mef is configured we can check the database
      CheckDatabase();

      _logger.Indent();
      try
      {
        _logger.LogDebug("Configuring View Engine");
        // Setup a custom view engine.
        // This knows how to deal with views in module folders.
        ViewEngines.Engines.Clear();

        // WARNING!!! Helpers assume that JonesieViewEngine is the first index in the ViewEngines array!!! Changing this
        // will break a lot of things.
        ViewEngines.Engines.Add(new JonesieViewEngine(MEFConfig.Container.GetExports<IViewModule>()));

        // Just the usual MVC startup fluff
        AreaRegistration.RegisterAllAreas();
        AuthConfig.RegisterAuth(_settings);
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

        // need to map the SignalR hub early
        RouteTable.Routes.MapHubs();

        // register routes for service and view modules and bundles for view modules
        ModuleConfig.RegisterRoutes(RouteTable.Routes, GlobalConfiguration.Configuration.Routes, _logger);
        ModuleConfig.RegisterBundles(BundleTable.Bundles, _logger);

        // now that everything else is done we can tell the modules to go ahead and get ready 
        ModuleConfig.InitialiseModules(_logger);

        // register the default routes and bundle after the modules
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        // we need to do this early so we can use IsInRole for security trimming the menus
        _logger.LogDebug("Initialising Web Security");
        WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", false);
      }
      finally
      {
        _logger.UnIndent();
      }

      _logger.LogDebug("Application Started");
    }