Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84c21ae

Browse files
committed
Ninject added and TranactionManager project
1 parent 882a178 commit 84c21ae

File tree

13 files changed

+293
-0
lines changed

13 files changed

+293
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using TransactionManager.Commands;
2+
3+
namespace TransactionManager.CommandHandlers
4+
{
5+
public interface IAmCommandHandler<TCommand> where TCommand : IAmCommand
6+
{
7+
void Handle(TCommand command);
8+
}
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace TransactionManager.Commands
2+
{
3+
public interface IAmCommand
4+
{
5+
}
6+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("TransactionManager")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("TransactionManager")]
13+
[assembly: AssemblyCopyright("Copyright © 2020")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("531e6001-6f44-45dc-a66c-9f5ec5ea67ef")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{531E6001-6F44-45DC-A66C-9F5EC5EA67EF}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>TransactionManager</RootNamespace>
11+
<AssemblyName>TransactionManager</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core" />
36+
<Reference Include="System.Xml.Linq" />
37+
<Reference Include="System.Data.DataSetExtensions" />
38+
<Reference Include="Microsoft.CSharp" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Net.Http" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="CommandHandlers\IAmCommandHandler.cs" />
45+
<Compile Include="Commands\IAmCommand.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
49+
</Project>

UniotOfWorkInMVC/UniotOfWorkInMVC.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29926.136
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniotOfWorkInMVC", "UniotOfWorkInMVC\UniotOfWorkInMVC.csproj", "{9E02B8BA-7601-43AA-91E4-F2AE52E79D85}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransactionManager", "TransactionManager\TransactionManager.csproj", "{531E6001-6F44-45DC-A66C-9F5EC5EA67EF}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{9E02B8BA-7601-43AA-91E4-F2AE52E79D85}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{9E02B8BA-7601-43AA-91E4-F2AE52E79D85}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{9E02B8BA-7601-43AA-91E4-F2AE52E79D85}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{531E6001-6F44-45DC-A66C-9F5EC5EA67EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{531E6001-6F44-45DC-A66C-9F5EC5EA67EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{531E6001-6F44-45DC-A66C-9F5EC5EA67EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{531E6001-6F44-45DC-A66C-9F5EC5EA67EF}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(UniotOfWorkInMVC.App_Start.NinjectWebCommon), "Start")]
2+
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(UniotOfWorkInMVC.App_Start.NinjectWebCommon), "Stop")]
3+
4+
namespace UniotOfWorkInMVC.App_Start
5+
{
6+
using System;
7+
using System.Web;
8+
9+
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
10+
11+
using Ninject;
12+
using Ninject.Web.Common;
13+
using Ninject.Web.Common.WebHost;
14+
using Ninject.Extensions.Conventions;
15+
using TransactionManager.Commands;
16+
using TransactionManager.CommandHandlers;
17+
18+
public static class NinjectWebCommon
19+
{
20+
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
21+
22+
/// <summary>
23+
/// Starts the application.
24+
/// </summary>
25+
public static void Start()
26+
{
27+
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
28+
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
29+
bootstrapper.Initialize(CreateKernel);
30+
}
31+
32+
/// <summary>
33+
/// Stops the application.
34+
/// </summary>
35+
public static void Stop()
36+
{
37+
bootstrapper.ShutDown();
38+
}
39+
40+
/// <summary>
41+
/// Creates the kernel that will manage your application.
42+
/// </summary>
43+
/// <returns>The created kernel.</returns>
44+
private static IKernel CreateKernel()
45+
{
46+
var kernel = new StandardKernel();
47+
try
48+
{
49+
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
50+
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
51+
RegisterServices(kernel);
52+
return kernel;
53+
}
54+
catch
55+
{
56+
kernel.Dispose();
57+
throw;
58+
}
59+
}
60+
61+
/// <summary>
62+
/// Load your modules or register your services here!
63+
/// </summary>
64+
/// <param name="kernel">The kernel.</param>
65+
private static void RegisterServices(IKernel kernel)
66+
{
67+
kernel.Bind(x => x.FromAssemblyContaining<IAmCommand>()
68+
.SelectAllClasses()
69+
.InheritedFrom(typeof(IAmCommand))
70+
.BindSingleInterface());
71+
kernel.Bind(x => x.FromAssemblyContaining<IAmCommandHandler<IAmCommand>>()
72+
.SelectAllClasses()
73+
.InheritedFromAny(typeof(IAmCommandHandler<>))
74+
.BindSingleInterface());
75+
}
76+
}
77+
}

UniotOfWorkInMVC/UniotOfWorkInMVC/UniotOfWorkInMVC.csproj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" />
34
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
45
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
56
<PropertyGroup>
@@ -48,6 +49,12 @@
4849
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
4950
<HintPath>..\packages\Castle.Core.4.2.0\lib\net45\Castle.Core.dll</HintPath>
5051
</Reference>
52+
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
53+
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
54+
</Reference>
55+
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
56+
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
57+
</Reference>
5158
<Reference Include="Microsoft.CSharp" />
5259
<Reference Include="Ninject, Version=3.3.4.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
5360
<HintPath>..\packages\Ninject.3.3.4\lib\net45\Ninject.dll</HintPath>
@@ -58,6 +65,12 @@
5865
<Reference Include="Ninject.Extensions.Factory, Version=3.3.2.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
5966
<HintPath>..\packages\Ninject.Extensions.Factory.3.3.2\lib\net45\Ninject.Extensions.Factory.dll</HintPath>
6067
</Reference>
68+
<Reference Include="Ninject.Web.Common, Version=3.3.2.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
69+
<HintPath>..\packages\Ninject.Web.Common.3.3.2\lib\net45\Ninject.Web.Common.dll</HintPath>
70+
</Reference>
71+
<Reference Include="Ninject.Web.Common.WebHost, Version=3.3.2.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
72+
<HintPath>..\packages\Ninject.Web.Common.WebHost.3.3.2\lib\net45\Ninject.Web.Common.WebHost.dll</HintPath>
73+
</Reference>
6174
<Reference Include="System" />
6275
<Reference Include="System.Data" />
6376
<Reference Include="System.Drawing" />
@@ -114,6 +127,9 @@
114127
<Reference Include="Newtonsoft.Json">
115128
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
116129
</Reference>
130+
<Reference Include="WebActivatorEx, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7b26dc2a43f6a0d4, processorArchitecture=MSIL">
131+
<HintPath>..\packages\WebActivatorEx.2.2.0\lib\net40\WebActivatorEx.dll</HintPath>
132+
</Reference>
117133
<Reference Include="WebGrease">
118134
<Private>True</Private>
119135
<HintPath>..\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
@@ -131,6 +147,7 @@
131147
<ItemGroup>
132148
<Compile Include="App_Start\BundleConfig.cs" />
133149
<Compile Include="App_Start\FilterConfig.cs" />
150+
<Compile Include="App_Start\NinjectWebCommon.cs" />
134151
<Compile Include="App_Start\RouteConfig.cs" />
135152
<Compile Include="Controllers\HomeController.cs" />
136153
<Compile Include="Global.asax.cs">
@@ -192,6 +209,12 @@
192209
<Content Include="Scripts\jquery-3.4.1.slim.min.map" />
193210
<Content Include="Scripts\jquery-3.4.1.min.map" />
194211
</ItemGroup>
212+
<ItemGroup>
213+
<ProjectReference Include="..\TransactionManager\TransactionManager.csproj">
214+
<Project>{531e6001-6f44-45dc-a66c-9f5ec5ea67ef}</Project>
215+
<Name>TransactionManager</Name>
216+
</ProjectReference>
217+
</ItemGroup>
195218
<PropertyGroup>
196219
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
197220
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
@@ -225,7 +248,10 @@
225248
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
226249
</PropertyGroup>
227250
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
251+
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
252+
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
228253
</Target>
254+
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" />
229255
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
230256
Other similar extension points exist, see Microsoft.Common.targets.
231257
<Target Name="BeforeBuild">

UniotOfWorkInMVC/UniotOfWorkInMVC/Web.config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
https://go.microsoft.com/fwlink/?LinkId=301880
55
-->
66
<configuration>
7+
<configSections>
8+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
9+
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
10+
</configSections>
711
<connectionStrings>
812
<add name="UnitOfWorkInMVCConnection" connectionString="dataSource=.\SQLEXPRESS;initialCatalog=UnitOfWorkInMVC;Integrated Security=True;" providerName="System.Data.SqlClient"></add>
913
</connectionStrings>
@@ -59,4 +63,9 @@
5963
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
6064
</compilers>
6165
</system.codedom>
66+
<entityFramework>
67+
<providers>
68+
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
69+
</providers>
70+
</entityFramework>
6271
</configuration>

UniotOfWorkInMVC/UniotOfWorkInMVC/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<package id="Antlr" version="3.5.0.2" targetFramework="net461" />
44
<package id="bootstrap" version="3.4.1" targetFramework="net461" />
55
<package id="Castle.Core" version="4.2.0" targetFramework="net461" />
6+
<package id="EntityFramework" version="6.4.4" targetFramework="net461" />
67
<package id="jQuery" version="3.4.1" targetFramework="net461" />
78
<package id="jQuery.Validation" version="1.17.0" targetFramework="net461" />
89
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net461" />
@@ -17,5 +18,8 @@
1718
<package id="Ninject" version="3.3.4" targetFramework="net461" />
1819
<package id="Ninject.Extensions.Conventions" version="3.3.0" targetFramework="net461" />
1920
<package id="Ninject.Extensions.Factory" version="3.3.2" targetFramework="net461" />
21+
<package id="Ninject.Web.Common" version="3.3.2" targetFramework="net461" />
22+
<package id="Ninject.Web.Common.WebHost" version="3.3.2" targetFramework="net461" />
23+
<package id="WebActivatorEx" version="2.2.0" targetFramework="net461" />
2024
<package id="WebGrease" version="1.6.0" targetFramework="net461" />
2125
</packages>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>

0 commit comments

Comments
 (0)