C# Class GSoft.Dynamite.ServiceLocator.AddOnProvidedServiceLocator

Special service locator which scans the GAC for DLLs that match the *.ServiceLocator.dll pattern for a ISharePointServiceLocatorAccessor to which it will delegate container provider duties. Thanks to these ServiceLocator-bootstrapping mechanics, you can build reusable "framework" SharePoint components that can have their inner implementations overrided by AddOns' registration module (since the AddOn's ServiceLocator is responsible for determining the final set of all registration modules that will be loaded).
Inheritance: ISharePointServiceLocator
Show file Open project: GSoft-SharePoint/Dynamite-2010

Private Properties

Property Type Description
EnsureServiceLocatorAccessor void
EnsureServiceLocatorAccessorForCurrentContext void
EnsureServiceLocatorAccessorForCurrentContext void
EnsureServiceLocatorAccessorForCurrentContext void
EnsureServiceLocatorAccessorForCurrentContext void
EnsureServiceLocatorAccessorForCurrentContext void
FindServiceLocatorAccessorType System.Type
FindServiceLocatorAccessorTypeNameFromMostSpecificPropertyBag string

Public Methods

Method Description
BeginLifetimeScope ( ) : ILifetimeScope

Creates a new child lifetime scope - a child to the most-nested currently available lifetime scope. In an HTTP-request context, will return a child scope to the shared per-request scope (allowing you to inject InstancePerSite, InstancePerWeb and InstancePerRequest-registered objects). Be sure to enable Dynamite's feature HttpModule feature: "GSoft.Dynamite.SP_Web Config Modifications" so that InstancePerRequest-scoped objects get properly disposed at the end of every HttpRequest. Outside an HTTP-request context, will return the a child of the root application container itself (preventing you from injecting InstancePerSite, InstancePerWeb or InstancePerRequest objects). If more than two DLLs exist in GAC that match the *.ServiceLocator.DLL filename pattern, and access to this member is responsible for DI bootstrapping at application startup, due to lack of context it will be impossible to disambiguate between the available containers. Use BeginLifetimeScope(SPFeature) or BeginLifetimeScope(SPWeb) or BeginLifetimeScope(SPSite) or BeginLifetimeScope(SPWebApplication) instead when outside an HTTP-request context (e.g. Cmdlets, FeatureActivated, etc.). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPWeb-SPSite-SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).

BeginLifetimeScope ( SPFarm farm ) : ILifetimeScope

Creates a new child lifetime scope under the root application container (objects registered as InstancePerSite, InstancePerWeb or InstancePerRequest will be inaccessible). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in the SPFarm property bag to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).

BeginLifetimeScope ( SPFeature feature ) : ILifetimeScope

Creates a new child lifetime scope that is as nested as possible, depending on the scope of the specified feature. In a SPSite or SPWeb-scoped feature context, will return a web-specific lifetime scope (allowing you to inject InstancePerSite and InstancePerWeb objects - InstancePerRequest scoped objects will be inaccessible). In a SPFarm or SPWebApplication feature context, will return a child container of the root application container (preventing you from injecting InstancePerSite, InstancePerWeb or InstancePerRequest objects). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPWeb-SPSite-SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).

BeginLifetimeScope ( SPSite site ) : ILifetimeScope

Creates a new child lifetime scope under the scope of the specified site collection (allowing you to inject InstancePerSite objects - InstancePerWeb and InstancePerRequest scoped objects will be inaccessible). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPSite-SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).

BeginLifetimeScope ( SPWeb web ) : ILifetimeScope

Creates a new child lifetime scope under the scope of the specified web (allowing you to inject InstancePerSite and InstancePerWeb objects - InstancePerRequest scoped objects will be inaccessible). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPWeb-SPSite-SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).

BeginLifetimeScope ( SPWebApplication webApplication ) : ILifetimeScope

Creates a new child lifetime scope under the root application container (objects registered as InstancePerSite, InstancePerWeb or InstancePerRequest will be inaccessible). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).

Private Methods

Method Description
EnsureServiceLocatorAccessor ( SPWeb web, SPSite site, SPWebApplication webApplication, SPFarm farm ) : void

Triggers ServiceLocator bootstrapping (scans the GAC for assemblies with a name that matches *.ServiceLocator.DLL, by convention).

EnsureServiceLocatorAccessorForCurrentContext ( ) : void
EnsureServiceLocatorAccessorForCurrentContext ( SPFarm farm ) : void
EnsureServiceLocatorAccessorForCurrentContext ( SPSite site ) : void
EnsureServiceLocatorAccessorForCurrentContext ( SPWeb web ) : void
EnsureServiceLocatorAccessorForCurrentContext ( SPWebApplication webApplication ) : void
FindServiceLocatorAccessorType ( Assembly assembly ) : Type

Loops through all Types in an assembly to find one that implements the ISharePointServiceLocatorAccessor interface, so that it can be used to access the preferred AddOn's ServiceLocator.

FindServiceLocatorAccessorTypeNameFromMostSpecificPropertyBag ( SPWeb web, SPSite site, SPWebApplication webApplication, SPFarm farm, string &locationWhereDiscriminatorWasFound ) : string

Inspects the property bags of all SPPersistedObjects in the context, from SPWeb to SPSite to SPWebApplication to SPFarm.

Method Details

BeginLifetimeScope() public method

Creates a new child lifetime scope - a child to the most-nested currently available lifetime scope. In an HTTP-request context, will return a child scope to the shared per-request scope (allowing you to inject InstancePerSite, InstancePerWeb and InstancePerRequest-registered objects). Be sure to enable Dynamite's feature HttpModule feature: "GSoft.Dynamite.SP_Web Config Modifications" so that InstancePerRequest-scoped objects get properly disposed at the end of every HttpRequest. Outside an HTTP-request context, will return the a child of the root application container itself (preventing you from injecting InstancePerSite, InstancePerWeb or InstancePerRequest objects). If more than two DLLs exist in GAC that match the *.ServiceLocator.DLL filename pattern, and access to this member is responsible for DI bootstrapping at application startup, due to lack of context it will be impossible to disambiguate between the available containers. Use BeginLifetimeScope(SPFeature) or BeginLifetimeScope(SPWeb) or BeginLifetimeScope(SPSite) or BeginLifetimeScope(SPWebApplication) instead when outside an HTTP-request context (e.g. Cmdlets, FeatureActivated, etc.). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPWeb-SPSite-SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).
public BeginLifetimeScope ( ) : ILifetimeScope
return ILifetimeScope

BeginLifetimeScope() public method

Creates a new child lifetime scope under the root application container (objects registered as InstancePerSite, InstancePerWeb or InstancePerRequest will be inaccessible). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in the SPFarm property bag to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).
public BeginLifetimeScope ( SPFarm farm ) : ILifetimeScope
farm SPFarm
return ILifetimeScope

BeginLifetimeScope() public method

Creates a new child lifetime scope that is as nested as possible, depending on the scope of the specified feature. In a SPSite or SPWeb-scoped feature context, will return a web-specific lifetime scope (allowing you to inject InstancePerSite and InstancePerWeb objects - InstancePerRequest scoped objects will be inaccessible). In a SPFarm or SPWebApplication feature context, will return a child container of the root application container (preventing you from injecting InstancePerSite, InstancePerWeb or InstancePerRequest objects). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPWeb-SPSite-SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).
public BeginLifetimeScope ( SPFeature feature ) : ILifetimeScope
feature SPFeature The current feature context from which we are requesting a child lifetime scope
return ILifetimeScope

BeginLifetimeScope() public method

Creates a new child lifetime scope under the scope of the specified site collection (allowing you to inject InstancePerSite objects - InstancePerWeb and InstancePerRequest scoped objects will be inaccessible). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPSite-SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).
public BeginLifetimeScope ( SPSite site ) : ILifetimeScope
site SPSite The current site collection from which we are requesting a child lifetime scope
return ILifetimeScope

BeginLifetimeScope() public method

Creates a new child lifetime scope under the scope of the specified web (allowing you to inject InstancePerSite and InstancePerWeb objects - InstancePerRequest scoped objects will be inaccessible). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPWeb-SPSite-SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).
public BeginLifetimeScope ( SPWeb web ) : ILifetimeScope
web SPWeb The current web from which we are requesting a child lifetime scope
return ILifetimeScope

BeginLifetimeScope() public method

Creates a new child lifetime scope under the root application container (objects registered as InstancePerSite, InstancePerWeb or InstancePerRequest will be inaccessible). If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') in one of the SPPersistedObject's property bags in the SPWebApp-SPFarm hierarchy to indicate which ServiceLocator should be used in your context. If the disambiguator setting cannot be found in any of the property bags in the hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used (preventing your AddOn registration modules from being loaded). Please dispose this lifetime scope when done (E.G. call this method from a using block).
public BeginLifetimeScope ( SPWebApplication webApplication ) : ILifetimeScope
webApplication SPWebApplication The current context's web application
return ILifetimeScope