-
Notifications
You must be signed in to change notification settings - Fork 0
/
option_provide.go
38 lines (32 loc) · 976 Bytes
/
option_provide.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2022 Sergey Novichkov. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
package di
type (
// ProvideOption is specified for Builder.Provide method option interface.
ProvideOption interface {
applyProvideOption(def *definition)
}
provideOptionFunc func(def *definition)
)
// provideOptionFunc implements the AddOption interface.
var _ ProvideOption = (*provideOptionFunc)(nil)
func (fn provideOptionFunc) applyProvideOption(def *definition) {
fn(def)
}
// ProvideOptions allow to organize logical groups of provide options.
//
// var builder = di.NewBuilder()
// builder.Provide(di.ProvideOptions(
// di.As(new(io.Writer)),
// di.Tags{{
// Name: "tag",
// }},
// ))
func ProvideOptions(options ...ProvideOption) ProvideOption {
return provideOptionFunc(func(def *definition) {
for _, o := range options {
o.applyProvideOption(def)
}
})
}