/// <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))); }
/// <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()); }
/// <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); }
/// <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)); }