Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rahulsahay19
Last active February 27, 2017 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulsahay19/8f166a316d966e1c430af70240ceba87 to your computer and use it in GitHub Desktop.
Save rahulsahay19/8f166a316d966e1c430af70240ceba87 to your computer and use it in GitHub Desktop.
RegisterTypes
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