Skip to content

Commit a43b78c

Browse files
Merge pull request #130 from efcore/fix-many-service-provders-created-warning
Prevent ManyServiceProvidersCreatedWarning exception (#129)
2 parents 4e3f7a7 + f9fffdb commit a43b78c

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/EFCore.FSharp/Extensions/ModelBuilderExtensions.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,18 @@ module Extensions =
102102
let useValueConverterForType (``type``: Type) (converter: ValueConverter) (modelBuilder: ModelBuilder) =
103103
modelBuilder.UseValueConverterForType(``type``, converter)
104104

105+
let fSharpTypeOptionsExtensionInstance = FSharpTypeOptionsExtension()
105106

106107
type DbContextOptionsBuilder with
107108
member this.UseFSharpTypes() =
108109
let extension =
109-
let finded =
110+
let found =
110111
this.Options.FindExtension<FSharpTypeOptionsExtension>()
111112

112-
if (box finded) <> null then
113-
finded
113+
if notNull found then
114+
found
114115
else
115-
FSharpTypeOptionsExtension()
116+
fSharpTypeOptionsExtensionInstance
116117

117118

118119
(this :> IDbContextOptionsBuilderInfrastructure)

src/EFCore.FSharp/Translations/Translation.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ type ExtensionInfo(extension) =
3030

3131
override _.LogFragment = "using FSharp types"
3232

33-
override _.ShouldUseSameServiceProvider other = other.IsDatabaseProvider
33+
override _.ShouldUseSameServiceProvider other = true
3434

35+
[<AllowNullLiteral>]
3536
type FSharpTypeOptionsExtension() =
3637
interface IDbContextOptionsExtension with
3738
member this.ApplyServices(services) =

tests/EFCore.FSharp.Tests/Translations/OptionTranslationTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type MyContext() =
2727

2828
override _.OnConfiguring(options: DbContextOptionsBuilder) : unit =
2929
options
30-
//.EnableServiceProviderCaching(false)
30+
.EnableServiceProviderCaching(false)
3131
.UseInMemoryDatabase("MyContext")
3232
.UseFSharpTypes()
3333
|> ignore

tests/EFCore.FSharp.Tests/Translations/SingleCaseUnionTranslationTests.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type MyContext() =
2929

3030
override _.OnConfiguring(options: DbContextOptionsBuilder) : unit =
3131
options
32+
.EnableServiceProviderCaching(false)
3233
.UseInMemoryDatabase("MyContext")
3334
.UseFSharpTypes()
3435
|> ignore

0 commit comments

Comments
 (0)