Created
June 2, 2016 14:56
-
-
Save treytomes/94ee7450bb9ed1afb267f54305b537da to your computer and use it in GitHub Desktop.
This VB.NET class will provide the glue between the StructureMap IOC library and Microsoft's CommonServiceLocator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports Microsoft.Practices.ServiceLocation | |
Imports StructureMap | |
Public Class StructureMapServiceLocator | |
Inherits ServiceLocatorImplBase | |
Private _Container As IContainer | |
Public Sub New(pContainer As IContainer) | |
_Container = pContainer | |
End Sub | |
Public Sub New(pRegistry As Registry) | |
Me.New(New Container(pRegistry)) | |
End Sub | |
''' <summary> | |
''' This method will do the actual work of resolving the requested service instance. | |
''' </summary> | |
''' <param name="pServiceType">Type of instance requested.</param> | |
''' <param name="pKey">Name of registered service you want. May be null.</param> | |
''' <returns> | |
''' The requested service instance. | |
''' </returns> | |
Protected Overrides Function DoGetInstance(pServiceType As Type, pKey As String) As Object | |
If String.IsNullOrWhiteSpace(pKey) Then | |
Return _Container.GetInstance(pServiceType) | |
Else | |
Return _Container.GetInstance(pServiceType, pKey) | |
End If | |
End Function | |
''' <summary> | |
''' This method will do the actual work of resolving all the requested service instances. | |
''' </summary> | |
''' <param name="pServiceType">Type of service requested.</param> | |
''' <returns> | |
''' Sequence of service instance objects. | |
''' </returns> | |
Protected Overrides Iterator Function DoGetAllInstances(pServiceType As Type) As IEnumerable(Of Object) | |
For Each oInstance As Object In _Container.GetAllInstances(pServiceType) | |
Yield oInstance | |
Next | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment