Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Created March 18, 2019 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gistlyn/7130a0deee31724d45763e8373efe264 to your computer and use it in GitHub Desktop.
Save gistlyn/7130a0deee31724d45763e8373efe264 to your computer and use it in GitHub Desktop.
Empty ASP.NET Core 2.1 LTS on .NET Framework ServiceStack App
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net47</TargetFramework>
<TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<Content Remove="appsettings.Development.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.*" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.*" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.*" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.*" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.*" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.*" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.*" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.*" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.*" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.*" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.*" />
<PackageReference Include="ServiceStack.Core" Version="5.*" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace MyApp
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyApp": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
using System;
using ServiceStack;
using MyApp.ServiceModel;
namespace MyApp.ServiceInterface
{
public class MyServices : Service
{
public object Any(Hello request)
{
return new HelloResponse { Result = $"Hello, {request.Name}!" };
}
}
}
using System;
using ServiceStack;
namespace MyApp.ServiceModel
{
[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello : IReturn<HelloResponse>
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Funq;
using ServiceStack;
using MyApp.ServiceInterface;
using MyApp.ServiceModel;
namespace MyApp
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration) => Configuration = configuration;
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
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, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseServiceStack(new AppHost
{
AppSettings = new NetCoreAppSettings(Configuration)
});
}
}
public class AppHost : AppHostBase
{
public AppHost() : base("My App", typeof(MyServices).Assembly) { }
// Configure your AppHost with the necessary configuration and dependencies your App needs
public override void Configure(Container container)
{
SetConfig(new HostConfig
{
DefaultRedirectPath = "/metadata",
DebugMode = HostingEnvironment.IsDevelopment()
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment