Created
June 3, 2016 09:56
-
-
Save daniiiol/a3c9d214dbe555dcb4550d7642d14c35 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/// <summary> | |
/// Specifies the Unity configuration for the main container. | |
/// </summary> | |
public class UnityConfig | |
{ | |
#region Unity Container | |
private static Lazy<IUnityContainer> container = new Lazy<IUnityContainer>(() => | |
{ | |
var container = new UnityContainer(); | |
RegisterTypes(container); | |
return container; | |
}); | |
/// <summary> | |
/// Gets the configured Unity container. | |
/// </summary> | |
public static IUnityContainer GetConfiguredContainer() | |
{ | |
return container.Value; | |
} | |
#endregion | |
/// <summary>Registers the type mappings with the Unity container.</summary> | |
/// <param name="container">The unity container to configure.</param> | |
/// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to | |
/// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> | |
public static void RegisterTypes(IUnityContainer container) | |
{ | |
var rootPath = HostingEnvironment.MapPath("~/"); | |
var basePath = PathInfo.Combine(PathInfo.Create(rootPath), PathInfo.Create(ConfigurationManager.AppSettings["NitroNet.BasePath"])).ToString(); | |
new DefaultUnityModule(basePath).Configure(container); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment