예제 #1
0
 /// <summary>
 /// Registers the WCF service routes within the implementing application's modules.
 /// </summary>
 private void RegisterServiceRoutes()
 {
     // Register service routes within each module
     foreach (IModuleRegistration module in BaseApplication.GetModules())
     {
         module.RegisterServiceRoutes(RouteTable.Routes);
     }
 }
예제 #2
0
 /// <summary>
 /// Registers css or javascript bundles for the application.
 /// </summary>
 /// <param name="bundles">The global bundle collection.</param>
 protected virtual void RegisterBundles(BundleCollection bundles)
 {
     BaseApplication.GetAssemblies()
     .ForEach(a =>
              a.GetInterfaceInstances <IBundleConfiguration>()
              .ForEach(b =>
                       b.RegisterBundles(bundles)));
     AppDomain.CurrentDomain.GetAssemblies()
     .ForEach(a =>
              a.GetInterfaceInstances <IBundleConfiguration>()
              .ForEach(b =>
                       b.RegisterBundles(bundles)));
 }
예제 #3
0
 /// <summary>
 /// Gets all areas found within the configured injection folder.
 /// </summary>
 /// <returns>
 /// Returns an array of <see cref="T:Geocrest.Web.Mvc.IModuleRegistration"/> instances.
 /// </returns>
 public static IModuleRegistration[] GetModules()
 {
     if (BaseApplication._allareas != null)
     {
         return(BaseApplication._allareas.ToArray());
     }
     // create new list and populate with configured areas
     BaseApplication._allareas = new List <IModuleRegistration>();
     foreach (Assembly a in BaseApplication.GetAssemblies())
     {
         BaseApplication._allareas.AddRange(a.GetInstances <ModuleRegistration>());
     }
     return(BaseApplication._allareas.ToArray());
 }
예제 #4
0
        /// <summary>
        /// Creates the kernel that will manage the application. When complete, will fire the
        /// <see cref="E:Geocrest.Web.Mvc.BaseApplication.KernelCreated"/> event.
        /// </summary>
        /// <returns>
        /// The created kernel.
        /// </returns>
        protected override Ninject.IKernel CreateKernel()
        {
            if (BaseApplication.Kernel != null)
            {
                return(BaseApplication.Kernel);
            }

            // Specify the factory that will handle MVC controller creation within areas.
            //ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());

            // Initialize the assemblies
            GetAssemblies();
            BaseApplication._kernel = new StandardKernel(new INinjectModule[] { new WebApiNinjectionModule() });
            //
            // WebApi2 Upgrade: (let Ninject set API resolver)
            //NinjectDependencyResolver res = new NinjectDependencyResolver(BaseApplication.Kernel);
            //GlobalConfiguration.Configuration.DependencyResolver = res;
            //

            // Register interfaces bound to classes
            BaseApplication.Kernel.Bind(scanner =>
                                        scanner.From(BaseApplication.GetAssemblies())
                                        .SelectAllClasses()
                                        .WithAttribute <NinjectionAttribute>()
                                        .BindAllInterfaces());

            // Register any modules that inherit from BaseNinjectModule or NinjectModule
            var loaded      = BaseApplication._kernel.GetModules();
            var loadedTypes = AppDomain.CurrentDomain.GetAssemblies().Concat(BaseApplication.GetAssemblies())
                              .SelectMany(x => x.GetTypes()
                                          .Where(t =>
                                                 (t.IsSubclassOf(typeof(NinjectModule)) ||
                                                  t.IsSubclassOf(typeof(BaseNinjectModule))) &&
                                                 !t.IsAbstract && t.GetConstructor(Type.EmptyTypes) != null &&
                                                 !BaseApplication._kernel.HasModule(t.FullName)));

            List <INinjectModule> modules = new List <INinjectModule>();

            loadedTypes.Distinct().ForEach(x => modules.AddIfNotNull((INinjectModule)Activator.CreateInstance(x)));
            BaseApplication.Kernel.Load(modules);

            // raise the kernel creation event
            this.OnKernelCreated(new KernelCreatedEventArgs(BaseApplication.Kernel));
            return(BaseApplication.Kernel);
        }
예제 #5
0
        /// <summary>
        /// Registers the areas that are found in the configured injection folder.
        /// </summary>
        private void RegisterAreas()
        {
            // Registers areas within the implementing application
            try
            {
                AreaRegistration.RegisterAllAreas();
            }
            catch { }

            // Register areas found within the configured injection folder
            foreach (IModuleRegistration module in BaseApplication.GetModules())
            {
                var    context = new AreaRegistrationContext(module.Area, RouteTable.Routes, null);
                string ns      = module.GetType().Namespace;

                if (ns != null)
                {
                    context.Namespaces.Add(ns + ".Controllers");
                }

                try
                {
                    module.RegisterArea(context);
                    //
                    // WebApi2 Upgrade:
                    GlobalConfiguration.Configure(module.RegisterHttpRoutes);
                    GlobalConfiguration.Configure(module.RegisterSamples);
                    //module.RegisterHttpRoutes(GlobalConfiguration.Configuration);
                    //module.RegisterSamples(GlobalConfiguration.Configuration);
                    //
                }
                catch (Exception ex)
                {
                    ErrorLog.GetDefault(null).Log(new Elmah.Error(new ModuleLoadException(module.Area, ex)));
                }
            }
        }
예제 #6
0
 /// <summary>
 /// Handles errors during assembly resolution
 /// </summary>
 /// <param name="sender">An object of the type <see cref="T:System.Object">Object</see>.</param>
 /// <param name="args">The <see cref="T:System.ResolveEventArgs"/> instance containing the event data.</param>
 /// <returns>
 /// Returns an instance of <see cref="T:System.Reflection.Assembly"/>
 /// </returns>
 public Assembly AssemblyResolve(object sender, ResolveEventArgs args)
 {
     return(BaseApplication.GetAssemblies().SingleOrDefault(a => a.FullName == args.Name));
 }