Skip to content

Commit

Permalink
Update sample to work with RTM (#1516)
Browse files Browse the repository at this point in the history
Modify sample for dependency-injection
  • Loading branch information
pranavkm authored and Rick-Anderson committed Jun 25, 2016
1 parent d2eebd2 commit 9b70958
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 67 deletions.
2 changes: 1 addition & 1 deletion aspnet/mvc/views/dependency-injection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The ``StatisticsService`` performs some calculations on the set of ``ToDoItem``
.. literalinclude:: dependency-injection/sample/src/ViewInjectSample/Model/Services/StatisticsService.cs
:linenos:
:language: c#
:emphasize-lines: 16,21,27
:emphasize-lines: 15,20,26

The sample repository uses an in-memory collection. The implementation shown above (which operates on all of the data in memory) is not recommended for large, remotely accessed data sets.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25402.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EE27383E-733E-49AF-84DF-DF446D31121D}"
EndProject
Expand All @@ -10,23 +10,23 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
global.json = global.json
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ViewInjectSample", "src\ViewInjectSample\ViewInjectSample.xproj", "{710841F4-996D-4EA5-A07E-1840C0B79EB1}"
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ViewInjectSample", "src\ViewInjectSample\ViewInjectSample.xproj", "{6B0F51DA-25F3-4F32-9161-D3043B17F09D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{710841F4-996D-4EA5-A07E-1840C0B79EB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{710841F4-996D-4EA5-A07E-1840C0B79EB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{710841F4-996D-4EA5-A07E-1840C0B79EB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{710841F4-996D-4EA5-A07E-1840C0B79EB1}.Release|Any CPU.Build.0 = Release|Any CPU
{6B0F51DA-25F3-4F32-9161-D3043B17F09D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B0F51DA-25F3-4F32-9161-D3043B17F09D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B0F51DA-25F3-4F32-9161-D3043B17F09D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B0F51DA-25F3-4F32-9161-D3043B17F09D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{710841F4-996D-4EA5-A07E-1840C0B79EB1} = {EE27383E-733E-49AF-84DF-DF446D31121D}
{6B0F51DA-25F3-4F32-9161-D3043B17F09D} = {EE27383E-733E-49AF-84DF-DF446D31121D}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion aspnet/mvc/views/dependency-injection/sample/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-rc1-update1"
"version": "1.0.0-preview2-003102"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNet.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace ViewInjectSample.Controllers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNet.Mvc;
using Microsoft.AspNetCore.Mvc;
using ViewInjectSample.Model;

namespace ViewInjectSample.Controllers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNet.Mvc;
using Microsoft.AspNetCore.Mvc;
using ViewInjectSample.Interfaces;

namespace ViewInjectSample.Controllers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using System.Threading.Tasks;
using ViewInjectSample.Interfaces;

namespace ViewInjectSample.Model.Services
Expand All @@ -13,26 +12,24 @@ public StatisticsService(IToDoItemRepository toDoItemRepository)
_toDoItemRepository = toDoItemRepository;
}

public async Task<int> GetCount()
public int GetCount()
{
return await Task.FromResult(_toDoItemRepository.List().Count());
return _toDoItemRepository.List().Count();
}

public async Task<int> GetCompletedCount()
public int GetCompletedCount()
{
return await Task.FromResult(
_toDoItemRepository.List().Count(x => x.IsDone));
return _toDoItemRepository.List().Count(x => x.IsDone);
}

public async Task<double> GetAveragePriority()
public double GetAveragePriority()
{
if (_toDoItemRepository.List().Count() == 0)
{
return 0.0;
}

return await Task.FromResult(
_toDoItemRepository.List().Average(x => x.Priority));
return _toDoItemRepository.List().Average(x => x.Priority);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using ViewInjectSample.Helpers;
using ViewInjectSample.Infrastructure;
Expand All @@ -26,16 +26,20 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=ToDo}/{action=Index}/{id?}");
});
app.UseMvc();
}

// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>710841f4-996d-4ea5-a07e-1840c0b79eb1</ProjectGuid>
<ProjectGuid>6b0f51da-25f3-4f32-9161-d3043b17f09d</ProjectGuid>
<RootNamespace>ViewInjectSample</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<DnxInvisibleContent Include="bower.json" />
<DnxInvisibleContent Include=".bowerrc" />
<DnxInvisibleContent Include="package.json" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<div>
<h1>To Do Items</h1>
<ul>
<li>Total Items: @await StatsService.GetCount()</li>
<li>Completed: @await StatsService.GetCompletedCount()</li>
<li>Avg. Priority: @await StatsService.GetAveragePriority()</li>
<li>Total Items: @StatsService.GetCount()</li>
<li>Completed: @StatsService.GetCompletedCount()</li>
<li>Avg. Priority: @StatsService.GetAveragePriority()</li>
</ul>
<table>
<tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},

"dependencies": {
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final"
},

"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0"
},

"frameworks": {
"dnx451": { },
"dnxcore50": { }
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
},
"net451": {}
},

"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
"publishOptions": {
"exclude": [
"**.user",
"**.vspscc"
]
}
}

0 comments on commit 9b70958

Please sign in to comment.