init odata
implemented simple access provided db context via DI
This commit is contained in:
77
API/API.Test/API.Test.csproj
Normal file
77
API/API.Test/API.Test.csproj
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props')" />
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{84714616-89D7-4A5D-86D8-2DC395530FEB}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>API.Test</RootNamespace>
|
||||||
|
<AssemblyName>API.Test</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
|
||||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||||
|
<IsCodedUITest>False</IsCodedUITest>
|
||||||
|
<TestProjectType>UnitTest</TestProjectType>
|
||||||
|
<NuGetPackageImportStamp>
|
||||||
|
</NuGetPackageImportStamp>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="UnitTest1.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
<PropertyGroup>
|
||||||
|
<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>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.props'))" />
|
||||||
|
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets'))" />
|
||||||
|
</Target>
|
||||||
|
<Import Project="..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.4.0\build\net45\MSTest.TestAdapter.targets')" />
|
||||||
|
</Project>
|
||||||
13
API/API.Test/App.config
Normal file
13
API/API.Test/App.config
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<configSections>
|
||||||
|
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||||
|
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||||
|
</configSections>
|
||||||
|
<entityFramework>
|
||||||
|
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
|
||||||
|
<providers>
|
||||||
|
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||||
|
</providers>
|
||||||
|
</entityFramework>
|
||||||
|
</configuration>
|
||||||
20
API/API.Test/Properties/AssemblyInfo.cs
Normal file
20
API/API.Test/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("API.Test")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("API.Test")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
[assembly: Guid("84714616-89d7-4a5d-86d8-2dc395530feb")]
|
||||||
|
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
43
API/API.Test/UnitTest1.cs
Normal file
43
API/API.Test/UnitTest1.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System;
|
||||||
|
using System.Data.Entity.Core.EntityClient;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
|
||||||
|
namespace API.Test {
|
||||||
|
[TestClass]
|
||||||
|
public class SqlConnectionBuilder {
|
||||||
|
[TestMethod]
|
||||||
|
public void Build() {
|
||||||
|
var serverName = "localhost\\SQLEXPRESS";
|
||||||
|
var databaseName = "wgenerator";
|
||||||
|
var user = "sa";
|
||||||
|
var pass = "sa";
|
||||||
|
|
||||||
|
// Initialize the connection string builder for the
|
||||||
|
// underlying provider.
|
||||||
|
var sqlBuilder =
|
||||||
|
new SqlConnectionStringBuilder {
|
||||||
|
|
||||||
|
// Set the properties for the data source.
|
||||||
|
DataSource = serverName,
|
||||||
|
InitialCatalog = databaseName,
|
||||||
|
IntegratedSecurity = true,
|
||||||
|
UserID= user,
|
||||||
|
Password = pass,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Build the SqlConnection connection string.
|
||||||
|
var providerString = sqlBuilder.ToString();
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine(providerString.ToString());
|
||||||
|
|
||||||
|
using (var conn =
|
||||||
|
new SqlConnection(providerString.ToString())) {
|
||||||
|
conn.Open();
|
||||||
|
Console.WriteLine("Just testing the connection.");
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
API/API.Test/packages.config
Normal file
6
API/API.Test/packages.config
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="EntityFramework" version="6.2.0" targetFramework="net462" />
|
||||||
|
<package id="MSTest.TestAdapter" version="1.4.0" targetFramework="net462" />
|
||||||
|
<package id="MSTest.TestFramework" version="1.4.0" targetFramework="net462" />
|
||||||
|
</packages>
|
||||||
12
API/API.sln
12
API/API.sln
@@ -5,6 +5,10 @@ VisualStudioVersion = 15.0.28307.489
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{27056FE2-5A34-44B2-9196-6F19C04F27CC}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{27056FE2-5A34-44B2-9196-6F19C04F27CC}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Test", "API.Test\API.Test.csproj", "{84714616-89D7-4A5D-86D8-2DC395530FEB}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Backend", "Backend", "{5DD4FA9B-976C-4CDB-9E73-CF3485DBDD72}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -15,10 +19,18 @@ Global
|
|||||||
{27056FE2-5A34-44B2-9196-6F19C04F27CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{27056FE2-5A34-44B2-9196-6F19C04F27CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{27056FE2-5A34-44B2-9196-6F19C04F27CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{27056FE2-5A34-44B2-9196-6F19C04F27CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{27056FE2-5A34-44B2-9196-6F19C04F27CC}.Release|Any CPU.Build.0 = Release|Any CPU
|
{27056FE2-5A34-44B2-9196-6F19C04F27CC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{84714616-89D7-4A5D-86D8-2DC395530FEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{84714616-89D7-4A5D-86D8-2DC395530FEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{84714616-89D7-4A5D-86D8-2DC395530FEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{84714616-89D7-4A5D-86D8-2DC395530FEB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{27056FE2-5A34-44B2-9196-6F19C04F27CC} = {5DD4FA9B-976C-4CDB-9E73-CF3485DBDD72}
|
||||||
|
{84714616-89D7-4A5D-86D8-2DC395530FEB} = {5DD4FA9B-976C-4CDB-9E73-CF3485DBDD72}
|
||||||
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {27650156-7B3F-4C0C-83D3-D13119DE083F}
|
SolutionGuid = {27650156-7B3F-4C0C-83D3-D13119DE083F}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
|||||||
@@ -56,7 +56,25 @@
|
|||||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.AspNet.OData, Version=7.1.0.21120, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.AspNet.OData.7.1.0\lib\net45\Microsoft.AspNet.OData.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.2.2.0\lib\net461\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.OData.Core, Version=7.5.4.30215, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.OData.Core.7.5.4\lib\portable-net45+win8+wpa81\Microsoft.OData.Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.OData.Edm, Version=7.5.4.30215, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.OData.Edm.7.5.4\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Spatial, Version=7.5.4.30215, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Spatial.7.5.4\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
@@ -66,6 +84,16 @@
|
|||||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="System.Reflection, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Runtime.Extensions, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Runtime.Extensions.4.3.1\lib\net462\System.Runtime.Extensions.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Web.Entity" />
|
<Reference Include="System.Web.Entity" />
|
||||||
<Reference Include="System.Web.ApplicationServices" />
|
<Reference Include="System.Web.ApplicationServices" />
|
||||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
@@ -98,9 +126,9 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="App_Start\Bootstrapper.cs" />
|
<Compile Include="App_Start\DependencyInjectionConfig.cs" />
|
||||||
<Compile Include="App_Start\WebApiConfig.cs" />
|
<Compile Include="App_Start\WebApiConfig.cs" />
|
||||||
<Compile Include="Controllers\ValuesController.cs" />
|
<Compile Include="Controllers\SongsController.cs" />
|
||||||
<Compile Include="Database\DataContext.cs" />
|
<Compile Include="Database\DataContext.cs" />
|
||||||
<Compile Include="Database\Model\Access.cs" />
|
<Compile Include="Database\Model\Access.cs" />
|
||||||
<Compile Include="Database\Model\Change.cs" />
|
<Compile Include="Database\Model\Change.cs" />
|
||||||
@@ -122,7 +150,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="favicon.ico" />
|
<Content Include="favicon.ico" />
|
||||||
<Content Include="Global.asax" />
|
<Content Include="Global.asax" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</Content>
|
||||||
<Content Include="Web.Debug.config">
|
<Content Include="Web.Debug.config">
|
||||||
<DependentUpon>Web.config</DependentUpon>
|
<DependentUpon>Web.config</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
@@ -130,9 +160,7 @@
|
|||||||
<DependentUpon>Web.config</DependentUpon>
|
<DependentUpon>Web.config</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup />
|
||||||
<Folder Include="App_Data\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
using Autofac;
|
|
||||||
using Autofac.Integration.WebApi;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Web.Http;
|
|
||||||
|
|
||||||
namespace API.App_Start
|
|
||||||
{
|
|
||||||
/// <remarks>
|
|
||||||
/// https://autofaccn.readthedocs.io/en/latest/integration/webapi.html#quick-start
|
|
||||||
/// </remarks>
|
|
||||||
public class Bootstrapper
|
|
||||||
{
|
|
||||||
public void InitContainer() {
|
|
||||||
var config = GlobalConfiguration.Configuration;
|
|
||||||
var builder = new ContainerBuilder();
|
|
||||||
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
|
|
||||||
builder.RegisterWebApiFilterProvider(config);
|
|
||||||
builder.RegisterWebApiModelBinderProvider();
|
|
||||||
|
|
||||||
RegisterServices(builder);
|
|
||||||
|
|
||||||
var container = builder.Build();
|
|
||||||
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RegisterServices(ContainerBuilder builder) {
|
|
||||||
// ... builder.RegisterType<object>();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
39
API/API/App_Start/DependencyInjectionConfig.cs
Normal file
39
API/API/App_Start/DependencyInjectionConfig.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using API.Database;
|
||||||
|
using Autofac;
|
||||||
|
using Autofac.Integration.WebApi;
|
||||||
|
using ProductService.Controllers;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Web.Http;
|
||||||
|
|
||||||
|
namespace API.App_Start {
|
||||||
|
/// <remarks>
|
||||||
|
/// https://autofaccn.readthedocs.io/en/latest/integration/webapi.html#quick-start
|
||||||
|
/// </remarks>
|
||||||
|
public static class DependencyInjectionConfig {
|
||||||
|
public static void RegisterDependecyInjection(this HttpConfiguration config) {
|
||||||
|
var builder = new ContainerBuilder();
|
||||||
|
builder.RegisterControllers();
|
||||||
|
builder.RegisterWebApiFilterProvider(config);
|
||||||
|
builder.RegisterWebApiModelBinderProvider();
|
||||||
|
|
||||||
|
builder.RegisterServices();
|
||||||
|
builder.RegisterDataProvider();
|
||||||
|
|
||||||
|
var container = builder.Build();
|
||||||
|
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RegisterControllers(this ContainerBuilder builder) {
|
||||||
|
builder.RegisterType<SongsController>().InstancePerRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RegisterServices(this ContainerBuilder builder) {
|
||||||
|
// ... builder.RegisterType<object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RegisterDataProvider(this ContainerBuilder builder) {
|
||||||
|
builder.RegisterType<DataContext>().InstancePerRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,34 @@
|
|||||||
using System;
|
using API.App_Start;
|
||||||
using System.Collections.Generic;
|
using API.Database.Model;
|
||||||
using System.Linq;
|
using Microsoft.AspNet.OData.Builder;
|
||||||
|
using Microsoft.AspNet.OData.Extensions;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
|
|
||||||
namespace API
|
namespace API {
|
||||||
{
|
public static class WebApiConfig {
|
||||||
public static class WebApiConfig
|
public static void Register(HttpConfiguration config) {
|
||||||
{
|
|
||||||
public static void Register(HttpConfiguration config)
|
|
||||||
{
|
|
||||||
// Web API configuration and services
|
// Web API configuration and services
|
||||||
|
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
|
||||||
|
|
||||||
// Web API routes
|
// Web API routes
|
||||||
config.MapHttpAttributeRoutes();
|
config.MapHttpAttributeRoutes();
|
||||||
|
|
||||||
config.Routes.MapHttpRoute(
|
config.Routes.MapHttpRoute(
|
||||||
name: "DefaultApi",
|
name: "DefaultApi",
|
||||||
routeTemplate: "api/{controller}/{id}",
|
routeTemplate: "api/{controller}/{id}",
|
||||||
defaults: new { id = RouteParameter.Optional }
|
defaults: new { id = RouteParameter.Optional }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Web API oData configuration
|
||||||
|
var builder = new ODataConventionModelBuilder();
|
||||||
|
builder.EntitySet<Song>("songs");
|
||||||
|
config.MapODataServiceRoute(
|
||||||
|
routeName: "songs",
|
||||||
|
routePrefix: "odata",
|
||||||
|
model: builder.GetEdmModel());
|
||||||
|
|
||||||
|
config.RegisterDependecyInjection();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
78
API/API/Controllers/SongsController.cs
Normal file
78
API/API/Controllers/SongsController.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
using API.Database;
|
||||||
|
using API.Database.Model;
|
||||||
|
using Microsoft.AspNet.OData;
|
||||||
|
using System.Data.Entity;
|
||||||
|
using System.Data.Entity.Infrastructure;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Web.Http;
|
||||||
|
namespace ProductService.Controllers {
|
||||||
|
public class SongsController : ODataController {
|
||||||
|
|
||||||
|
public SongsController(DataContext db) {
|
||||||
|
this.db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly DataContext db;
|
||||||
|
|
||||||
|
private bool ProductExists(int key) {
|
||||||
|
return db.Songs.Any(p => p.ID == key);
|
||||||
|
}
|
||||||
|
|
||||||
|
[EnableQuery]
|
||||||
|
public IQueryable<Song> Get() {
|
||||||
|
return db.Songs;
|
||||||
|
}
|
||||||
|
|
||||||
|
[EnableQuery]
|
||||||
|
public SingleResult<Song> Get([FromODataUri] int key) {
|
||||||
|
var result = db.Songs.Where(p => p.ID == key);
|
||||||
|
return SingleResult.Create(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IHttpActionResult> Post(Song song) {
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
|
||||||
|
db.Songs.Add(song);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return Created(song);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Song> product) {
|
||||||
|
if (!ModelState.IsValid) {
|
||||||
|
return BadRequest(ModelState);
|
||||||
|
}
|
||||||
|
var entity = await db.Songs.FindAsync(key);
|
||||||
|
if (entity == null) return NotFound();
|
||||||
|
|
||||||
|
product.Patch(entity);
|
||||||
|
try {
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
} catch (DbUpdateConcurrencyException) {
|
||||||
|
if (!ProductExists(key)) return NotFound();
|
||||||
|
|
||||||
|
throw;
|
||||||
|
|
||||||
|
}
|
||||||
|
return Updated(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IHttpActionResult> Put([FromODataUri] int key, Song update) {
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
if (key != update.ID) return BadRequest();
|
||||||
|
|
||||||
|
db.Entry(update).State = EntityState.Modified;
|
||||||
|
try {
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
} catch (DbUpdateConcurrencyException) {
|
||||||
|
if (!ProductExists(key)) return NotFound();
|
||||||
|
|
||||||
|
throw;
|
||||||
|
|
||||||
|
}
|
||||||
|
return Updated(update);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Web.Http;
|
|
||||||
|
|
||||||
namespace API.Controllers
|
|
||||||
{
|
|
||||||
public class ValuesController : ApiController
|
|
||||||
{
|
|
||||||
// GET api/values
|
|
||||||
public IEnumerable<string> Get()
|
|
||||||
{
|
|
||||||
return new string[] { "value1", "value2" };
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET api/values/5
|
|
||||||
public string Get(int id)
|
|
||||||
{
|
|
||||||
return "value";
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST api/values
|
|
||||||
public void Post([FromBody]string value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// PUT api/values/5
|
|
||||||
public void Put(int id, [FromBody]string value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// DELETE api/values/5
|
|
||||||
public void Delete(int id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,9 @@
|
|||||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||||
</configSections>
|
</configSections>
|
||||||
|
<connectionStrings>
|
||||||
|
<add name="DataContext" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=wgenerator;Integrated Security=True;User ID=sa;Password=sa" providerName="System.Data.SqlClient" />
|
||||||
|
</connectionStrings>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="webpages:Version" value="3.0.0.0" />
|
<add key="webpages:Version" value="3.0.0.0" />
|
||||||
<add key="webpages:Enabled" value="false" />
|
<add key="webpages:Enabled" value="false" />
|
||||||
@@ -61,6 +64,34 @@
|
|||||||
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
|
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.OData.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.5.4.30215" newVersion="7.5.4.30215" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.OData.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.5.4.30215" newVersion="7.5.4.30215" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-7.5.4.30215" newVersion="7.5.4.30215" />
|
||||||
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
<entityFramework>
|
<entityFramework>
|
||||||
|
|||||||
@@ -4,10 +4,28 @@
|
|||||||
<package id="Autofac" version="4.9.1" targetFramework="net462" />
|
<package id="Autofac" version="4.9.1" targetFramework="net462" />
|
||||||
<package id="Autofac.WebApi2" version="4.2.0" targetFramework="net462" />
|
<package id="Autofac.WebApi2" version="4.2.0" targetFramework="net462" />
|
||||||
<package id="EntityFramework" version="6.2.0" targetFramework="net462" />
|
<package id="EntityFramework" version="6.2.0" targetFramework="net462" />
|
||||||
|
<package id="Microsoft.AspNet.OData" version="7.1.0" targetFramework="net462" />
|
||||||
<package id="Microsoft.AspNet.WebApi" version="5.2.7" targetFramework="net462" />
|
<package id="Microsoft.AspNet.WebApi" version="5.2.7" targetFramework="net462" />
|
||||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net462" />
|
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net462" />
|
||||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net462" />
|
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net462" />
|
||||||
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net462" />
|
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net462" />
|
||||||
|
<package id="Microsoft.Extensions.DependencyInjection" version="2.2.0" targetFramework="net462" />
|
||||||
|
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.2.0" targetFramework="net462" />
|
||||||
|
<package id="Microsoft.OData.Core" version="7.5.4" targetFramework="net462" />
|
||||||
|
<package id="Microsoft.OData.Edm" version="7.5.4" targetFramework="net462" />
|
||||||
|
<package id="Microsoft.Spatial" version="7.5.4" targetFramework="net462" />
|
||||||
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net462" />
|
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net462" />
|
||||||
|
<package id="System.Collections" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.ComponentModel" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.Globalization" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.Linq" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.Reflection" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.Runtime.Extensions" version="4.3.1" targetFramework="net462" />
|
||||||
|
<package id="System.Threading" version="4.3.0" targetFramework="net462" />
|
||||||
|
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net462" />
|
||||||
<package id="WebGrease" version="1.6.0" targetFramework="net462" />
|
<package id="WebGrease" version="1.6.0" targetFramework="net462" />
|
||||||
</packages>
|
</packages>
|
||||||
Reference in New Issue
Block a user