The Inject
attribute is for Property setter injection only. Constructor injection is implicit. Just create your bindings and then make a kernel.Get<Blah>()
and Blah
is created using constructor injection.
F# Ninject Constructor Injection
質問
Is it possible to do implicit constructor injection in F# using Ninject? If so, how?
I tried to put the [<Inject>]
attribute on the type definition, but I got back an error that it's invalid.
Here is what I tried:
[<Inject>]
type Blah(x : ISword) =
解決
他のヒント
The spec allows this as follows:
class-type-defn :=
type-name primary-constr-args_opt object-val_opt '=' class class-type-body end
where
primary-constr-args :=
attributes_opt accessopt (simple-pat, ... , simple-pat)
As a result, you just need to change your code to
type Blah [<Inject>](x : ISword) =
Here's Constructor Injection in F#:
type Foo(bar : IBar) =
// class members etc. here
Any library that requires you to slap an attribute on the type in order to understand that, is doing something wrong; pick another library.
所属していません StackOverflow