Skip to content

Instantly share code, notes, and snippets.

@DotNetNerd
Created May 8, 2013 08:48
Show Gist options
  • Save DotNetNerd/5539136 to your computer and use it in GitHub Desktop.
Save DotNetNerd/5539136 to your computer and use it in GitHub Desktop.
Sample of using Unity from F#
open Microsoft.Practices.Unity
type IRepository =
abstract member FindPhoneNumber : string -> string
type Repository() =
interface IRepository with
member this.FindPhoneNumber(name) = match name with "John" -> "87654321" | _ -> ""
let container = new UnityContainer() :> IUnityContainer
UnityContainerExtensions.RegisterType<IRepository, Repository>(container) |> ignore
// Or
// let Repository =
// {
// new IRepository with
// member this.FindPhoneNumber(name) = match name with "Elisabeth" -> "87654321" | _ -> ""
// }
// UnityContainerExtensions.RegisterInstance<IRepository>(container, Repository) |> ignore
let myInstance = UnityContainerExtensions.Resolve<IRepository>(container)
let phone = myInstance.FindPhoneNumber "John"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment