build

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 5 Imported by: 54

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCreateError

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

NewCreateError 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 any) *errors.ApplicationError

NewCreateErrorByLocator creates an error instance and assigns its values.

Parameters:
	- correlationId string
	- locator any human-readable locator of the component that cannot be created.
Returns: *errors.ApplicationError

Types

type CompositeFactory

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

CompositeFactory 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(context.Background(), loggerLocator);
		Result: Descriptor("pip-service", "logger", "null", "default", "1.0")
	factory.Create(context.Background(), loggerLocator);    // Result: created NullLogger

func NewCompositeFactory

func NewCompositeFactory() *CompositeFactory

NewCompositeFactory creates a new instance of the factory. Returns: *CompositeFactory

func NewCompositeFactoryFromFactories

func NewCompositeFactoryFromFactories(factories ...IFactory) *CompositeFactory

NewCompositeFactoryFromFactories 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)

Add a factory into the list of embedded factories.

Parameters:
	- factory IFactory a factory to be added.

func (*CompositeFactory) CanCreate

func (c *CompositeFactory) CanCreate(locator any) any

CanCreate 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 any a locator to identify component to be created.
Returns: any  a locator for a component that the factory is able to create.

func (*CompositeFactory) Create

func (c *CompositeFactory) Create(locator any) (any, error)

Create creates a component identified by given locator.

Parameters:
	- locator any a locator to identify component to be created.
Returns: any, 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)

Remove 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

NewFactory create new factory

Returns: *Factory

func (*Factory) CanCreate

func (c *Factory) CanCreate(locator any) any

CanCreate 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 any a locator to identify component to be created.
Returns: any a locator for a component that the factory is able to create.

func (*Factory) Create

func (c *Factory) Create(locator any) (any, error)

Create a component identified by given locator.

Parameters:
	- locator any a locator to identify component to be created.
Returns: any, 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 any, factory func(locator any) any)

Register registers a component using a factory method.

Parameters:
	- locator any a locator to identify component to be created.
	- factory func(locator any) any a factory function that receives a locator and returns a created component.

func (*Factory) RegisterType

func (c *Factory) RegisterType(locator any, factory any)

RegisterType registers a component using its type (a constructor function).

Parameters:
	- locator any a locator to identify component to be created.
	- factory any a factory.

type IFactory

type IFactory interface {

	// CanCreate 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 any) any

	// Create a component identified by given locator.
	// Return a CreateError if the factory is not able to create the component.
	Create(locator any) (any, error)
}

IFactory 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