forked from unoplatform/Elmish.Uno
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sample configuration code for IOptions pattern usage
- Loading branch information
1 parent
4deaf14
commit dcc4b94
Showing
6 changed files
with
94 additions
and
49 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/Templates/SolutionTemplate/SolutionTemplate/Configuration.fs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[<CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>] | ||
module SolutionTemplate.Configuration | ||
|
||
open System | ||
open System.Linq | ||
open Microsoft.Extensions.Configuration | ||
open Microsoft.Extensions.Hosting | ||
open Xamarin.Essentials | ||
|
||
module Environments = | ||
let LocalAPI = "LocalAPI" | ||
|
||
let configure (ctx : HostBuilderContext) (builder : IConfigurationBuilder) = | ||
|
||
let environmentName = ctx.HostingEnvironment.EnvironmentName | ||
|
||
let inMemoryCollection = seq { | ||
|
||
yield! | ||
match environmentName with | ||
| name when name.Equals(Environments.LocalAPI, StringComparison.CurrentCultureIgnoreCase) -> | ||
let endpoint = | ||
if DeviceInfo.Platform = DevicePlatform.Android | ||
then "http://10.0.2.2:7071/GraphQL" | ||
else "http://localhost:7071/GraphQL" | ||
seq { | ||
yield struct("GraphQL:EndPoint", endpoint) | ||
} | ||
| name when name.Equals(Environments.Development, StringComparison.CurrentCultureIgnoreCase) -> | ||
seq { | ||
yield struct("GraphQL:EndPoint", "https://host.net/GraphQL") | ||
} | ||
| name when name.Equals(Environments.Production, StringComparison.CurrentCultureIgnoreCase) -> | ||
seq { | ||
yield struct("GraphQL:EndPoint", "https://host.net/GraphQL") | ||
} | ||
| _ -> raise <| NotSupportedException () | ||
|
||
//yield struct("AzureMaps:Key", BingAutocomplete.key) | ||
} | ||
|
||
builder.AddInMemoryCollection (inMemoryCollection.ToDictionary(fstv, sndv)) |> ignore | ||
() | ||
|
||
[<CLIMutable>] | ||
type GraphQLSettings = | ||
{ EndPoint : string } | ||
|
||
open Microsoft.Extensions.DependencyInjection | ||
|
||
type IServiceCollection with | ||
member services.ConfigureSolutionTemplateOptions (configuration : IConfiguration) = | ||
services.Configure<GraphQLSettings>(configuration.GetSection("GraphQL")) |
2 changes: 1 addition & 1 deletion
2
...lutionTemplate/SolutionTemplate/Elmish.fs → ...mplate/SolutionTemplate/Helpers/Elmish.fs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace SolutionTemplate.Elmish1 | ||
namespace SolutionTemplate.ElmishProgram | ||
|
||
[<AutoOpen>] | ||
module State = | ||
|
15 changes: 15 additions & 0 deletions
15
src/Templates/SolutionTemplate/SolutionTemplate/Helpers/ObjAndStructConversions.fs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace SolutionTemplate | ||
|
||
module ValueOption = | ||
let toOption value = | ||
match value with | ValueSome v -> Some v | _ -> None | ||
|
||
module Option = | ||
let toVOption value = | ||
match value with | Some v -> ValueSome v | _ -> ValueNone | ||
|
||
[<AutoOpen>] | ||
module ValueTuple = | ||
|
||
let fstv struct (a,_) = a | ||
let sndv struct (_,b) = b |
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
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
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