Working full stack forums get

This commit is contained in:
2017-06-12 13:37:48 +03:00
parent b4d10b7bff
commit aeb18aa75b
23 changed files with 484 additions and 15 deletions

View File

@@ -1,3 +1,6 @@
using BL.Interfaces;
using DAL.Repositories;
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(WebApi.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(WebApi.App_Start.NinjectWebCommon), "Stop")]
@@ -10,6 +13,11 @@ namespace WebApi.App_Start
using Ninject;
using Ninject.Web.Common;
using System.Web.Http;
using Ninject.Web.WebApi;
using DAL;
using DAL.Interfaces;
using BL.Services;
public static class NinjectWebCommon
{
@@ -46,6 +54,10 @@ namespace WebApi.App_Start
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
// Support WebAPI
GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
return kernel;
}
catch
@@ -61,6 +73,10 @@ namespace WebApi.App_Start
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
}
kernel.Bind<IFoorumDbContext>().To<FoorumDbContext>().InRequestScope();
kernel.Bind<IFoorumRepository>().To<FoorumRepository>().InRequestScope();
kernel.Bind<IPostRepository>().To<PostRepository>().InRequestScope();
kernel.Bind<IFoorumService>().To<FoorumService>().InRequestScope();
}
}
}

View File

@@ -45,7 +45,7 @@ namespace WebApi
// Force always json response
var jsonFormatter = new JsonMediaTypeFormatter();
//optional: set serializer settings here
config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter));
//config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter));
}
}
}

View File

@@ -4,15 +4,22 @@ using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BL.DTOs;
using BL.Interfaces;
namespace WebApi.Controllers
{
public class FoorumController : ApiController
{
// GET api/<controller>
public IEnumerable<string> Get()
private IFoorumService _foorumService;
public FoorumController(IFoorumService foorumService)
{
return new string[] { "value1", "value2" };
_foorumService = foorumService;
}
// GET api/<controller>
public IEnumerable<FoorumDTO> Get()
{
return _foorumService.GetAll();
}
// GET api/<controller>/5

View File

@@ -4,7 +4,14 @@
https://go.microsoft.com/fwlink/?LinkId=301879
-->
<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>
<appSettings></appSettings>
<connectionStrings>
<add name="FoorumDb" connectionString="Data Source=(localdb)\mssqllocaldb;Initial Catalog=FoorumDb;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
@@ -35,6 +42,10 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
@@ -43,4 +54,14 @@
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>

View File

@@ -43,6 +43,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\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.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
</Reference>
@@ -57,7 +63,10 @@
<HintPath>..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath>
</Reference>
<Reference Include="Ninject.Web.Common, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.Web.Common.3.2.0.0\lib\net45-full\Ninject.Web.Common.dll</HintPath>
<HintPath>..\packages\Ninject.Web.Common.3.2.3.0\lib\net45-full\Ninject.Web.Common.dll</HintPath>
</Reference>
<Reference Include="Ninject.Web.WebApi, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.Web.WebApi.3.2.4.0\lib\net45-full\Ninject.Web.WebApi.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Web.DynamicData" />
@@ -80,7 +89,7 @@
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="WebActivatorEx, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7b26dc2a43f6a0d4, processorArchitecture=MSIL">
<HintPath>..\packages\WebActivatorEx.2.0\lib\net40\WebActivatorEx.dll</HintPath>
<HintPath>..\packages\WebActivatorEx.2.2.0\lib\net40\WebActivatorEx.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@@ -96,6 +105,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Global.asax" />
<Content Include="index.html" />
<Content Include="Web.config" />
</ItemGroup>
<ItemGroup>
@@ -120,6 +130,16 @@
<Folder Include="App_Data\" />
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BL\BL.csproj">
<Project>{e9e385e4-c36a-42b0-8424-bc2d075916f2}</Project>
<Name>BL</Name>
</ProjectReference>
<ProjectReference Include="..\DAL\DAL.csproj">
<Project>{b783887a-e5bb-4066-9b9b-abd7b4c1e269}</Project>
<Name>DAL</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@@ -1,2 +1,16 @@
<h1>api</h1>
<a href="/api/foorum">foorum</a>
<a href="/api/foorum">foorum</a>
<button onclick="getForums()">GetAll</button>
<code><pre id="output"></pre></code>
<script>
function getForums() {
var out = document.getElementById("output");
fetch("/api/foorum").then(resp => {
return resp.json();
}).then(data => {
console.log(data);
out.innerText = JSON.stringify(data, null, 2);
});
}
</script>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
@@ -10,7 +11,8 @@
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
<package id="Ninject" version="3.2.2.0" targetFramework="net452" />
<package id="Ninject.Web.Common" version="3.2.0.0" targetFramework="net452" />
<package id="Ninject.Web.Common" version="3.2.3.0" targetFramework="net452" />
<package id="Ninject.Web.Common.WebHost" version="3.2.3.0" targetFramework="net452" />
<package id="WebActivatorEx" version="2.0" targetFramework="net452" />
<package id="Ninject.Web.WebApi" version="3.2.4.0" targetFramework="net452" />
<package id="WebActivatorEx" version="2.2.0" targetFramework="net452" />
</packages>