Created
May 8, 2013 08:48
-
-
Save DotNetNerd/5539136 to your computer and use it in GitHub Desktop.
Sample of using Unity from F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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