Last active
February 27, 2017 13:16
-
-
Save rahulsahay19/8f166a316d966e1c430af70240ceba87 to your computer and use it in GitHub Desktop.
RegisterTypes
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
public static void RegisterTypes(IUnityContainer container) | |
{ | |
// NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. | |
//container.LoadConfiguration(); | |
// TODO: Register your types here | |
CreateFactory(container); | |
} | |
private static void CreateFactory(IUnityContainer container) | |
{ | |
var clientSection = GetClientSection(); | |
//Logic to read the endpoints and construct assembly on the fly | |
for (int i = 0; i < clientSection.Endpoints.Count; i++) | |
{ | |
var contract = clientSection.Endpoints[i].Contract; | |
var typeParts = contract.Split('.'); | |
var constructAssembly = ""; | |
var endPointName = clientSection.Endpoints[i].Name; | |
Assembly inassembly = null; | |
if (inassembly != null) | |
foreach (Type ti in inassembly.GetTypes().Where(x => x.IsInterface)) | |
{ | |
if (ti.GetCustomAttributes(true).OfType<ServiceContractAttribute>().Any()) | |
{ | |
var incomingInterface = ti; | |
container.RegisterType(incomingInterface, | |
new TransientLifetimeManager(), | |
new InjectionFactory( | |
c => CreateGenericFactory(incomingInterface) | |
)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment