This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## IIS WebAdmin Module | |
Import-Module WebAdministration | |
$AppPoolInstance = Get-Item IIS:\AppPools\$AppPool | |
Write-Output "Set Site PreLoadEnabled to true" | |
Set-ItemProperty IIS:\Sites\$Site -name applicationDefaults.preloadEnabled -value True | |
Write-Output "Set Recycling.periodicRestart.time = 0" | |
$AppPoolInstance.Recycling.periodicRestart.time = [TimeSpan]::Parse("0"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ignore local appSettings | |
appSettings.Local.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AddCommentHandler : IHandleMessages<AddComment> | |
{ | |
public async Task Handle(AddComment message, IMessageHandlerContext context) | |
{ | |
var cosmosSession = context.SynchronizedStorageSession.CosmosPersistenceSession(); | |
var postResource = await cosmosSession.Container.ReadItemAsync<Post>(message.PostId, | |
new PartitionKey(message.PostId)); | |
if (postResource == null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AddPostHandler : IHandleMessages<AddPost> | |
{ | |
public async Task Handle(AddPost message, IMessageHandlerContext context) | |
{ | |
var cosmosSession = context.SynchronizedStorageSession.CosmosPersistenceSession(); | |
var post = new Post(message.PostId, message.Title, message.Description, message.Author); | |
cosmosSession.Batch.CreateItem(post); | |
await context.Publish(new PostCreated | |
{ | |
PostId = post.PostId, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Post | |
{ | |
public Post(string postId, | |
string title, | |
string description, | |
string author) | |
{ | |
Id = postId; | |
PostId = postId; | |
Title = title; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PostIdAsPartitionKeyBehavior: Behavior<IIncomingLogicalMessageContext> | |
{ | |
public override Task Invoke(IIncomingLogicalMessageContext context, Func<Task> next) | |
{ | |
if (context.Message.Instance is IPostIdPartitionKey partitionKey) | |
{ | |
var partitionKeyValue = partitionKey.PostId; | |
context.Extensions.Set(new PartitionKey(partitionKeyValue)); | |
return next(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await Host.CreateDefaultBuilder(args) | |
.UseNServiceBus((_ => | |
{ | |
var endpointConfiguration = new EndpointConfiguration("Samples.Worker"); | |
var transport = endpointConfiguration.UseTransport<LearningTransport>(); | |
transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive); | |
endpointConfiguration.UsePersistence<CosmosPersistence>() | |
// Using Cosmos emulator | |
.CosmosClient(new CosmosClient( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IPostIdPartitionKey | |
{ | |
string PostId { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.MapPost("/create", async (IMessageSession messageSession, [FromBody] Post post) => | |
{ | |
var addPostCommand = new Messages.AddPost(post.Title, post.Description, post.Author); | |
await messageSession.Send(addPostCommand); | |
return Results.Accepted(null, new { addPostCommand.PostId }); | |
}); | |
app.MapPost("/add-comment", async (IMessageSession messageSession, [FromBody] Comment comment) => | |
{ | |
var addCommentCommand = new Messages.AddComment(comment.PostId, comment.Content, comment.CommentBy); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder.Services.AddEndpointsApiExplorer(); | |
builder.Services.AddSwaggerGen(options => | |
{ | |
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Posts Api", Version = "v1" }); | |
}); | |
var app = builder.Build(); | |
. | |
. | |
app.UseHttpsRedirection() |
NewerOlder