Added templates to include in ASP.NET MVC project.

This commit is contained in:
Alessandro Calorì 2017-10-23 20:27:57 +02:00
Родитель 0d83fd14cc
Коммит 77e75af62a
4 изменённых файлов: 95 добавлений и 5 удалений

Просмотреть файл

@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
VisualStudioVersion = 15.0.27004.2005
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unity.Mvc", "src\Unity.Mvc.csproj", "{EECD2BD0-11FC-4A97-8187-E2CA7A744CC4}"
EndProject

Просмотреть файл

@ -2,9 +2,9 @@
<PropertyGroup>
<Description>Unity MVC</Description>
<Version>5.0.0</Version>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<FileVersion>5.0.0.0</FileVersion>
<Version>5.0.1</Version>
<AssemblyVersion>5.0.1.0</AssemblyVersion>
<FileVersion>5.0.1.0</FileVersion>
<Copyright>Copyright © Microsoft 2008</Copyright>
<PackageProjectUrl>https://github.com/unitycontainer/unity</PackageProjectUrl>
<RepositoryUrl>https://github.com/unitycontainer/unity</RepositoryUrl>
@ -17,6 +17,11 @@
<Company>Microsoft.Practices.Unity</Company>
</PropertyGroup>
<ItemGroup>
<Compile Include="content\App_Start\UnityConfig.cs.pp" />
<Compile Include="content\App_Start\UnityMvcActivator.cs.pp" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Web" />
</ItemGroup>
@ -40,9 +45,9 @@
<TargetFramework>net47</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.3" />
<PackageReference Include="WebActivatorEx" Version="2.2.0" />
</ItemGroup>
<PropertyGroup>

Просмотреть файл

@ -0,0 +1,47 @@
using System;
using Unity;
namespace $rootnamespace$
{
/// <summary>
/// Specifies the Unity configuration for the main container.
/// </summary>
public static class UnityConfig
{
#region Unity Container
private static Lazy<IUnityContainer> container =
new Lazy<IUnityContainer>(() =>
{
var container = new UnityContainer();
RegisterTypes(container);
return container;
});
/// <summary>
/// Configured Unity Container.
/// </summary>
public static IUnityContainer Container => 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)
{
// NOTE: To load from web.config uncomment the line below.
// Make sure to add a Unity.Configuration to the using statements.
// container.LoadConfiguration();
// TODO: Register your type's mappings here.
// container.RegisterType<IProductRepository, ProductRepository>();
}
}
}

Просмотреть файл

@ -0,0 +1,38 @@
using System.Linq;
using System.Web.Mvc;
using Unity.Mvc;
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(UnityMvcActivator), nameof(UnityMvcActivator.Start))]
[assembly: WebActivatorEx.ApplicationShutdownMethod(typeof(UnityMvcActivator), nameof(UnityMvcActivator.Shutdown))]
namespace $rootnamespace$
{
/// <summary>
/// Provides the bootstrapping for integrating Unity with ASP.NET MVC.
/// </summary>
public static class UnityMvcActivator
{
/// <summary>
/// Integrates Unity when the application starts.
/// </summary>
public static void Start()
{
FilterProviders.Providers.Remove(FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().First());
FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(UnityConfig.Container));
DependencyResolver.SetResolver(new UnityDependencyResolver(UnityConfig.Container));
// TODO: Uncomment if you want to use PerRequestLifetimeManager
// Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
}
/// <summary>
/// Disposes the Unity container when the application is shut down.
/// </summary>
public static void Shutdown()
{
UnityConfig.Container.Dispose();
}
}
}