Skip to content

Commit

Permalink
Upgrade to v8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Feb 6, 2024
1 parent e49ec20 commit 3cd8e9b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 26 deletions.
7 changes: 3 additions & 4 deletions MyApp.ServiceModel/Hello.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

namespace MyApp.ServiceModel;

[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello : IReturn<HelloResponse>
public class Hello : IGet, IReturn<HelloResponse>
{
public string Name { get; set; }
public required string Name { get; set; }
}

public class HelloResponse
{
public string Result { get; set; }
public required string Result { get; set; }
}
15 changes: 4 additions & 11 deletions MyApp/Configure.AppHost.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
using Funq;
using ServiceStack;
using MyApp.ServiceInterface;

[assembly: HostingStartup(typeof(MyApp.AppHost))]
[assembly: HostingStartup(typeof(MyApp.AppHost))]

namespace MyApp;

public class AppHost : AppHostBase, IHostingStartup
public class AppHost() : AppHostBase("MyApp"), IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => {
// Configure ASP.NET Core IOC Dependencies
});

public AppHost() : base("MyApp", typeof(MyServices).Assembly) {}

public override void Configure(Container container)
public override void Configure()
{
// Configure ServiceStack only IOC, Config & Plugins
// Configure ServiceStack, Run custom logic after ASP.NET Core Startup
SetConfig(new HostConfig {
UseSameSiteCookies = true,
});
}
}
4 changes: 4 additions & 0 deletions MyApp/MyApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.*" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.*" />
<PackageReference Include="ServiceStack" Version="8.*" />
<PackageReference Include="ServiceStack.Extensions" Version="8.*" />
<PackageReference Include="ServiceStack.AspNetCore.OpenApi" Version="8.*" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 25 additions & 5 deletions MyApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
var builder = WebApplication.CreateBuilder(args);
using MyApp.ServiceInterface;

var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;

services.AddServiceStack(typeof(MyServices).Assembly, c =>
{
c.AddSwagger();
});

services.AddEndpointsApiExplorer();
services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
if (app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
}
app.UseServiceStack(new AppHost());

app.UseStaticFiles();

app.UseServiceStack(new AppHost(), options => {
options.MapEndpoints();
});

app.Run();
9 changes: 6 additions & 3 deletions MyApp/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
h2, h3, strong { font-weight:500 }
</style>
<link rel="stylesheet" href="https://unpkg.com/@highlightjs/[email protected]/styles/atom-one-dark.min.css">
<script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js"></script><!--safari polyfill-->
<script type="importmap">
{
"imports": {
Expand All @@ -28,10 +27,10 @@ <h2><a href="/ui/Hello">Hello</a> API</h2>
<div id="result"></div>

<script type="module">
import { JsonApiClient, $1, on } from '@servicestack/client'
import { JsonServiceClient, $1, on } from '@servicestack/client'
import { Hello } from '/types/mjs'

const client = JsonApiClient.create()
const client = new JsonServiceClient()
on('#txtName', {
/** @param {Event} el */
async keyup(el) {
Expand All @@ -53,6 +52,10 @@ <h2><a href="/ui/Hello">Hello</a> API</h2>
- [View API Details](/ui/Hello?tab=details)
- [Browse API source code in different langauges](/ui/Hello?tab=code)

## View in Swagger UI
- [Swagger UI](/swagger/index.html)
- [Open API v3 JSON](/swagger/v1/swagger.json)

### Using JsonServiceClient in Web Pages

Easiest way to call APIs is to use [@servicestack/client](https://docs.servicestack.net/javascript-client) with
Expand Down
6 changes: 3 additions & 3 deletions MyApp/wwwroot/js/dtos.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Options:
Date: 2023-02-09 11:00:41
Version: 6.60
Date: 2024-02-06 15:04:23
Version: 8.10
Tip: To override a DTO option, remove "//" prefix before updating
BaseUrl: https://localhost:5001
Expand All @@ -25,7 +25,7 @@ export class Hello {
/** @type {string} */
name;
getTypeName() { return 'Hello' }
getMethod() { return 'POST' }
getMethod() { return 'GET' }
createResponse() { return new HelloResponse() }
}

0 comments on commit 3cd8e9b

Please sign in to comment.