ObjectFactory

Implements a generic IObjectFactory.

Namespace:
Inetdev.Context
Type:
Class
Public:
Yes
Protected:
No
Sealed:
No
Abstract:
Yes
Inherits from:
System.Object
Implements:
Inetdev.Context.IObjectFactory, System.IDisposable

Constructors

ObjectFactory

Default constructor

Signature:
protected Void ObjectFactory()

Properties

Name

Application context object factory name.

Signature:
public String Name { get; set; }

Methods

ContainsObject

Finds out if the factory contains an object of the given name.

Signature:
public Boolean ContainsObject(name)
Returns

true if the factory contains the object.

Parameters
Name Type Summary
name String Name of the object to find.
Exceptions
Type Summary
ArgumentNullOrEmptyException Thrown when name is null or empty.

ContainsObject

Finds out if the factory contains an object of the given type.

Signature:
public Boolean ContainsObject(objectType)
Returns

true if the factory contains the object.

Parameters
Name Type Summary
objectType Type Type of the object to find.
Exceptions
Type Summary
ArgumentNullException Thrown when objectType is null.

CreateInstance

Creates a new instance of the application context object.

Signature:
protected Object CreateInstance(cfg, args)
Returns

A newly created instance of the application context object.

Parameters
Name Type Summary
cfg ObjectConfiguration Object configuration.
args Object[] Arguments to pass to the constructor.
Exceptions
Type Summary
ArgumentNullException Thrown when cfg is null.

Dispose

Performs a clean up.

Signature:
public Void Dispose()

GetObject

Gets an initialized instance of an object for the given name.

Signature:
public Object GetObject(name)
Returns

An initialized instance of the object named name.

Parameters
Name Type Summary
name String The name of the object to retrieve.
Exceptions
Type Summary
ArgumentNullOrEmptyException Thrown when name is null or empty.

GetObject

Gets an initialized instance of an object for the given name. If there isn´t an object for the given name or if there is an error getting the object, an exception is thrown only if thrown is true otherwise null is returned.

Signature:
public Object GetObject(name, thrown)
Returns

An initialized instance of the object named name.

Parameters
Name Type Summary
name String The name of the object to retrieve.
thrown Boolean Whether to throw an exception of not.
Exceptions
Type Summary
ArgumentNullOrEmptyException Thrown when name is null or empty.
NoSuchObjectException Thrown when there are no object for the given name and thrown is true.

GetObject

Gets an instance of the object for the given name.

Signature:
public Object GetObject(name, args)
Returns

An initialized instance of the object named name.

Parameters
Name Type Summary
name String The name of the object to retrieve.
args Object[] Arguments to be passed to the constructor.
Exceptions
Type Summary
ArgumentNullOrEmptyException Thrown when name is null or empty.
NoSuchObjectException Thrown when there isn't an object for the given name.

GetObject

Gets an initialized instance of a object for the given name only if the object type is equal to requiredType.

Signature:
public Object GetObject(name, requiredType)
Returns

An initialized instance of the object named name.

Parameters
Name Type Summary
name String The name of the object to retrieve.
requiredType Type Required Type of the object.
Exceptions
Type Summary
ArgumentNullOrEmptyException Thrown when name is null or empty.
NoSuchObjectException Thrown when there isn't an object for the given name.
ObjectNotOfRequiredTypeException Thown the the object is not of type requiredType.

GetObject

Gets an initialized instance of the object for the given objectType.

Signature:
public Object GetObject(objectType)
Returns

An initialized instance of the object for the given type.

Parameters
Name Type Summary
objectType Type Type of the object to retrive.
Exceptions
Type Summary
ArgumentNullException Thrown when objectType is null.
NoSuchObjectException Thrown when there are no object for the given type.

GetObject

Gets an initialized instance of the object for the given objectType.

Signature:
public Object GetObject(objectType, args)
Returns

An initialized instance of the object for the given type.

Parameters
Name Type Summary
objectType Type Type of the object to retrive.
args Object[] Arguments to pass to the constructor.
Exceptions
Type Summary
ArgumentNullException Thrown when objectType is null.
NoSuchObjectException Thrown when there are no object for the given type.

GetObject

Gets an initialized instance of an object of type .

Signature:
public GetObject<T>()
Returns

An initialized object of type .

GetObject

Gets an initialized instance of an object of type .

Signature:
public GetObject<T>(args)
Returns

An initialized object of type .

Parameters
Name Type Summary
args Object[] Arguments to be passed to the constructor.
Exceptions
Type Summary
NoSuchObjectException Thrown when there are no objects of the specified type.

GetObjectsOfContextAssignableFrom

Gets a collection of initialized objects from the application context that are assignable from .

Signature:
public IEnumerable GetObjectsOfContextAssignableFrom<T>()
Returns

A collection of initialized application context objects.

GetObjectsOfContextAssignableFrom

Gets a collection of initialized objects from the application context that are assignable from type.

Signature:
public IEnumerable<Object> GetObjectsOfContextAssignableFrom(type)
Returns

A collection of initialized application context objects.

Parameters
Name Type Summary
type Type Type that the objects must be assignable from.
Exceptions
Type Summary
ArgumentNullException Thrown when type is null.

GetType

Gets the Type of the object for the given name.

Signature:
public Type GetType(name)
Returns

Type of the object for the given name.

Parameters
Name Type Summary
name String The name of the object to retrive it's type.
Exceptions
Type Summary
ArgumentNullOrEmptyException Thrown when name is null or empty.
NoSuchObjectException Thrown when there are no object for the given name.

InitializeFactory

Initialize this object factory from the enumeration of configured objects.

Signature:
protected Void InitializeFactory(name, config)
Parameters
Name Type Summary
name String Name of this factory.
config IEnumerable<ObjectConfiguration> A collection of object configuration for this factory.
Exceptions
Type Summary
ArgumentNullOrEmptyException Thrown when name is null or empty.
ArgumentNullException Thown when config is null.

InjectDependencies

Inject dependencies into o.

Signature:
public Void InjectDependencies(name, o)
Parameters
Name Type Summary
name String The name of the application context object.
o Object An object to inject dependencies into.
Exceptions
Type Summary
ArgumentNullOrEmptyException Thrown when name is null or empty.
ArgumentNullException Thrown when o is null.
NoSuchObjectException Thrown when there are no object for the given name.
DependencyInjectionException Thrown when an error occurs while injecting dependencies.

InjectDependencies

Inject dependencies into o.

Signature:
protected Void InjectDependencies(cfg, o)
Parameters
Name Type Summary
cfg ObjectConfiguration Object configuration.
o Object An object to inject dependencies into.
Exceptions
Type Summary
ArgumentNullException Thrown when any of the arguments is null.
DependencyInjectionException Thrown when an error occurs while injecting dependencies.

IsSingleton

Finds out whether the object for the given name is a singleton.

Signature:
public Boolean IsSingleton(name)
Returns

true if the object is a singleton.

Parameters
Name Type Summary
name String The name of the object.
Exceptions
Type Summary
ArgumentNullOrEmptyException Thrown when name is null or empty.
NoSuchObjectException Thrown when there are no object for the given name.

ToString

Returns a textual representation of the object factory.

Signature:
public String ToString()