build

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 5 Imported by: 36

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCreateError

func NewCreateError(correlationId string, message string) *errors.ApplicationError

Creates an error instance and assigns its values. Parameters:

  • correlationId string
  • message string human-readable error of the component that cannot be created.

Returns *errors.ApplicationError

func NewCreateErrorByLocator

func NewCreateErrorByLocator(correlationId string, locator interface{}) *errors.ApplicationError

Creates an error instance and assigns its values. Parameters:

  • correlationId string
  • locator interface{} human-readable locator of the component that cannot be created.

Returns *errors.ApplicationError

Types

type CompositeFactory

type CompositeFactory struct {
	// contains filtered or unexported fields
}

Aggregates multiple factories into a single factory component. When a new component is requested, it iterates through factories to locate the one able to create the requested component.

This component is used to conveniently keep all supported factories in a single place.

Example

factory := NewCompositeFactory();
factory.Add(NewDefaultLoggerFactory());
factory.Add(NewDefaultCountersFactory());

loggerLocator := NewDescriptor("*", "logger", "*", "*", "1.0");
factory.CanCreate(loggerLocator);         // Result: Descriptor("pip-service", "logger", "null", "default", "1.0")
factory.Create(loggerLocator);             // Result: created NullLogger

func NewCompositeFactory

func NewCompositeFactory() *CompositeFactory

Creates a new instance of the factory. Returns *CompositeFactory

func NewCompositeFactoryFromFactories

func NewCompositeFactoryFromFactories(factories ...IFactory) *CompositeFactory

Creates a new instance of the factory. Parameters:

  • factories ...IFactory a list of factories to embed into this factory.

Returns *CompositeFactory

func (*CompositeFactory) Add

func (c *CompositeFactory) Add(factory IFactory)

Adds a factory into the list of embedded factories. Parameters:

  • factory IFactory a factory to be added.

func (*CompositeFactory) CanCreate

func (c *CompositeFactory) CanCreate(locator interface{}) interface{}

Checks if this factory is able to create component by given locator. This method searches for all registered components and returns a locator for component it is able to create that matches the given locator. If the factory is not able to create a requested component is returns null. Parameters:

  • locator interface{} a locator to identify component to be created.

Returns interface{} a locator for a component that the factory is able to create.

func (*CompositeFactory) Create

func (c *CompositeFactory) Create(locator interface{}) (interface{}, error)

Creates a component identified by given locator. Parameters:

  • locator interface{} a locator to identify component to be created.

Returns interface{}, error the created component and a CreateError if the factory is not able to create the component..

func (*CompositeFactory) Remove

func (c *CompositeFactory) Remove(factory IFactory)

Removes a factory from the list of embedded factories. Parameters:

  • factory IFactory the factory to remove.

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

func NewFactory

func NewFactory() *Factory

Create new factory Return *Factory

func (*Factory) CanCreate

func (c *Factory) CanCreate(locator interface{}) interface{}

Checks if this factory is able to create component by given locator. This method searches for all registered components and returns a locator for component it is able to create that matches the given locator. If the factory is not able to create a requested component is returns null. Parameters:

  • locator interface{} a locator to identify component to be created.

Returns interface{} a locator for a component that the factory is able to create.

func (*Factory) Create

func (c *Factory) Create(locator interface{}) (interface{}, error)

Creates a component identified by given locator. Parameters:

  • locator interface{} a locator to identify component to be created.

Returns interface{}, error the created component and a CreateError if the factory is not able to create the component.

func (*Factory) Register

func (c *Factory) Register(locator interface{}, factory func(locator interface{}) interface{})

Registers a component using a factory method. Parameters:

  • locator interface{} a locator to identify component to be created. factory func() interface{} a factory function that receives a locator and returns a created component.

func (*Factory) RegisterType

func (c *Factory) RegisterType(locator interface{}, factory interface{})

Registers a component using its type (a constructor function). Parameters:

  • locator interface{} a locator to identify component to be created.
  • factory interface{} a factory.

type IFactory

type IFactory interface {
	// Checks if this factory is able to create component by given locator.
	// This method searches for all registered components and returns a locator for component it is able to create that matches the given locator. If the factory is not able to create a requested component is returns null.
	CanCreate(locator interface{}) interface{}
	// Creates a component identified by given locator.
	// Return a CreateError if the factory is not able to create the component.
	Create(locator interface{}) (interface{}, error)
}

Interface for component factories.

Factories use locators to identify components to be created.

The locators are similar to those used to locate components in references. They can be of any type like strings or integers. However Pip.Services toolkit most often uses Descriptor objects as component locators.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL