RegisterScope adds a new scope with the specified name to the registry.
(name string, scope Scope)
| 443 | |
| 444 | // RegisterScope adds a new scope with the specified name to the registry. |
| 445 | func (d *DefaultContainer) RegisterScope(name string, scope Scope) error { |
| 446 | if strings.TrimSpace(name) == "" { |
| 447 | return ErrInvalidScopeName |
| 448 | } |
| 449 | |
| 450 | if scope == nil { |
| 451 | return errors.New("nil scope") |
| 452 | } |
| 453 | |
| 454 | if SingletonScope != name && PrototypeScope != name { |
| 455 | d.muScopes.Lock() |
| 456 | defer d.muScopes.Unlock() |
| 457 | |
| 458 | d.scopes[name] = scope |
| 459 | return nil |
| 460 | } |
| 461 | |
| 462 | return ErrScopeReplacementNotAllowed |
| 463 | } |
| 464 | |
| 465 | // Scope retrieves the scope associated with the given name. |
| 466 | // Returns the scope and a boolean indicating its existence. |
no outgoing calls