servicestack

What's the best way to respond with the correct content type from request filter in ServiceStack?

对着背影说爱祢 提交于 2019-12-04 04:23:43
问题 ServiceStack services are great for responding with the content type that's requested in the Accept header. But if I need to close/end the response early from within a request filter, is there a way to respond with the proper content type? All I have access to in a request filter is the raw IHttpResponse so it seems to me that the only option is to tediously, manually check the Accept header and do a bunch of switch/case statements to figure out which serializer to use and then write directly

Implementing WebHooks with ServiceStack

旧城冷巷雨未停 提交于 2019-12-04 03:09:29
I'm currently working on a REST service allowing to control and monitor some physical devices. The corresponding REST API is largely based on principles and ideas you can find in the following article: " Controlling and Monitoring Devices with REST ". The monitored and controlled devices can generate some events to which clients must be able to subscribe. My idea was to implement that part using RESTful WebHooks . So whenever an event arises, my service makes a REST API callback to each subscriber in order to notify it. My question, now: What would be a proper way to implement this scenario

How to use Dapper in ServiceStack

◇◆丶佛笑我妖孽 提交于 2019-12-04 03:07:28
Currently, I am using OrmLite for DB operations. I am also planning to use Dapper ORM, but can anyone point me how to integrate DapperORM in ServiceStack. Do I need to implement both IDbConnection and IDbConnectionFactory interfaces with Dapper and plugin into the container. public override void Configure(Container container) { container.Register<IDbConnectionFactory>( c => new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["default"].ConnectionString, SqlServerDialect.Provider)); container.Register<IDbConnection>(c => c.Resolve<IDbConnectionFactory>().OpenDbConnection())

Transactions in the Repository Pattern using ServiceStack.ORMLite

不打扰是莪最后的温柔 提交于 2019-12-04 02:50:00
I'm implementing Repository Pattern using ServiceStack.ORMLite like this: public class MyRepository : IMyRepository { private IDbConnectionFactory DbConnectionFactory = null; public MyRepository(IDbConnectionFactory dbConnectionFactory) { DbConnectionFactory = dbConnectionFactory; } public void MyMethod() { using (var connection = DbConnectionFactory.OpenDbConnection()) using (var cmd = connection.CreateCommand()) { //Do something here } } } But I don't know how to handle DbTransaction when I need to warp some DB operation in a DbTransaction.It looks like TransactionScope is a solution but I

Is F# aware of its discriminated unions' compiled forms?

本秂侑毒 提交于 2019-12-04 02:23:26
A discriminated union in F# is compiled to an abstract class and its options become nested concrete classes. type DU = A | B DU is abstract while DU.A and DU.B are concrete. With ServiceStack, the serialization of types to JSON strings and back can be customized with functions. With respect to the DU type, here's how I could do it in C#. using ServiceStack.Text; JsConfig<DU.A>.SerializeFn = v => "A"; // Func<DU.A, String> JsConfig<DU.B>.SerializeFn = v => "B"; // Func<DU.B, String> JsConfig<DU>.DeserializeFn = s => if s == "A" then DU.NewA() else DU.NewB(); // Func<String, DU> Is F# aware of

More ServiceStack request DTO advice

旧时模样 提交于 2019-12-04 01:46:33
问题 This is a follow up regarding: ServiceStack Request DTO design In the above question the design was strictly regarding read operations. What about write operations? Say we wanted to add operations for creating a new booking limit, would reusing the noun be appropriate here? [Route("/bookinglimits/","POST")] public class CreateBookingLimit : IReturn<BookingLimit> { BookingLimit newBookingLimit } -OR- Would this be better design? [Route("/bookinglimits/","POST")] public class CreateBookingLimit

Serialize C# Enum Definition to Json

断了今生、忘了曾经 提交于 2019-12-03 22:18:43
Given the following in C#: [Flags] public enum MyFlags { None = 0, First = 1 << 0, Second = 1 << 1, Third = 1 << 2, Fourth = 1 << 3 } Are there any existing methods in ServiceStack.Text for serializing to the following JSON? { "MyFlags": { "None": 0, "First": 1, "Second": 2, "Third": 4, "Fourth": 8 } } Currently I'm using the routine below, are there better ways to do this? public static string ToJson(this Type type) { var stringBuilder = new StringBuilder(); Array values = Enum.GetValues(type); stringBuilder.Append(string.Format(@"{{ ""{0}"": {{", type.Name)); foreach (Enum value in values) {

Why ServiceStack.Text doesn't default dates to iso8601?

自闭症网瘾萝莉.ら 提交于 2019-12-03 22:18:16
If I use Newtonsoft.Json.NET it defaults to iso8601 (i.e.: 2011-06-02T09:34:29+02:00 ) for serializing/deserializing dates. Why ServiceStack.Text doesn't default to this and I need to specify it as a configuration setting? mythz ServiceStack followed the .NET DataContractSerializer defaults, not JSON.NET. We are reluctant to make breaking changes like this, especially when there's an easy way to configure it otherwise with: JsConfig.DateHandler = DateHandler.ISO8601; 来源: https://stackoverflow.com/questions/11882987/why-servicestack-text-doesnt-default-dates-to-iso8601

Is there a way to host Razor pages in console application using ServiceTask?

我是研究僧i 提交于 2019-12-03 21:48:52
问题 I'm trying to make a console application to expose JSON services. In addition I'd like to host html and js pages to use them. I put the *.md (even *.htm) files into Views folder, but I can't reach them. If I add a route ".Add("/Test")" (where MyMarkdownView : MarkdownViewBase), i even get a "KeyNotFoundException The given key was not present in the dictionary." exception. Is it generally possible, or I should make my own service (similar to https://github.com/jimschubert/blogs/blob/master

Redis Expire does not work

时间秒杀一切 提交于 2019-12-03 19:40:24
问题 I use ServiceStack.Redis (build from the latest sources: https://github.com/ServiceStack/ServiceStack.Redis/tree/master/src). I do something like this: CacheRecord foundKey = cacheRecords.GetById(p_sParentKey); ... CacheRecord cacheRecord = cacheRecords.Store(foundKey); ... redisClient.Expire(p_sParentKey, validityPeriodInMinutes * 60); i tried to debug using Console.WriteLine(cacheRecords.GetTimeToLive(p_sParentKey)); which returns -00:00:01 . it doesnt matter which value i assign to