I've translated this code from c# and would like it to be more idiomatic f#:
namespace Foo.App_Start
open System
open System.Web
open Microsoft.Web.Infrastructure.DynamicModuleHelper
open Ninject
open Ninject.Web.Common
type NinjectResolver(kernel:IKernel) =
let _kernel = kernel
interface System.Web.Http.Dependencies.IDependencyResolver with
member this.BeginScope():Http.Dependencies.IDependencyScope = upcast this
member this.GetService(t) =
_kernel.TryGet(t)
member this.GetServices(t)=
_kernel.GetAll(t)
member this.Dispose() = ()
//was static
[<AbstractClass; Sealed>]
type NinjectWebCommon () =
static let bootstrapper = new Bootstrapper()
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
//private static void RegisterServices(IKernel kernel)
static let RegisterServices(kernel:IKernel) =
System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver <- new NinjectResolver(kernel)
do()
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
//private static IKernel CreateKernel()
static let KernelCreation(kernel:IKernel) =
System.Diagnostics.Debug.WriteLine "kernel Creation!"
RegisterServices(kernel)
let bs = fun () -> new Bootstrapper()
let kernelFun= System.Func<IKernel> (fun () -> bs().Kernel)
kernel.Bind<System.Func<IKernel>>().ToMethod(fun ac -> kernelFun) |> ignore
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>() |> ignore
let fetchedKernel:IKernel =System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof<IKernel>) :?> IKernel
fetchedKernel
static let CreateKernel():IKernel =
System.Diagnostics.Debug.WriteLine "standard kernel creating!"
let kernel= new StandardKernel()
//
try //RegisterServices(kernel) |> ignore;
KernelCreation(kernel)
with
| ex ->
System.Diagnostics.Debug.WriteLine "kernel disposing!"
kernel.Dispose()
raise ex
/// <summary>
/// Starts the application
/// </summary>
static member Start() =
DynamicModuleUtility.RegisterModule typedefof<OnePerRequestHttpModule> |> ignore
DynamicModuleUtility.RegisterModule typedefof<NinjectHttpModule> |> ignore
bootstrapper.Initialize(System.Func<_>(CreateKernel))
System.Diagnostics.Debug.WriteLine "app Start()"
//
//
/// <summary>
/// Stops the application.
/// </summary>
static member Stop() =
System.Diagnostics.Debug.WriteLine "app stop"
bootstrapper.ShutDown()
module DummyModuleToAttachAssemblyAttribute =
[<assembly: WebActivatorEx.PreApplicationStartMethod(typeof<NinjectWebCommon>, "Start")>]
////[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(FLochart.App_Start.NinjectWebCommon), "Stop")]
[<assembly: WebActivatorEx.ApplicationShutdownMethod(typeof<NinjectWebCommon>, "Stop")>]
do()