Khosla Tech Blog: Musings on Technology

Architectural guide to unify business rule and input pattern validation without compromising on code readability

In ISCP we started validating requests with ServiceStack Fluent Validation (about five years ago). This was limited to pure input pattern validation (let's call it field validation) with no regards to correctness of the same in relation to the data in the database (business validation). The latter was done inside service method (if required). Later we introduced a service-agnostic manager layer and moved logic from service methods to managers. At managers we opted to creating separate validator types to offload business validation logic from manager methods for readability purposes.

Continue reading

Opt in mechanism to generate ServiceStack API documentation

For one of our clients we built an API driven platform which could be consumed in two ways, either as a service using our front end or by integrating third party UI interfaces with the API. As one could guess API documentation plays a vital role in usability of such systems. We use ServiceStack as our web services framework and API documentation generation is built into the framework. The generated documentation is a JSON file that conforms to Open API, which is a specification and complete framework implementation for describing, producing, consuming, and visualizing restful web services.

Continue reading

Self-hosting documentation securely for an API platform with granular control on who can see what using filter policies

Requirements Recently we've embarked on an adventure to move online documentation of an API platform for one of our clients from ReadMe to a self-hosted solution chiefly to provide granular access control capability required by the business. Self-hosting of documentation has two main elements: Endpoints – This is the API reference section with OpenAPI specification for each endpoint Articles – This section contains how-tos and other articles related to the system, workflows and security.

Continue reading

Applying template method design pattern

Recently I worked on refactoring a piece of code which dealt with filtering DB entities based on certain attributes and there were different types of such filters each doing almost the same thing and the problem was, how to reuse the common logic while making sure that the specific details of filtering are the only thing each filter will have to worry about. To better explain the problem and its solution, consider an example of a banking system, different entities in the system are the client (the account holder), account, deposit, withdrawal, investment, investment sale, etc.

Continue reading

Automate generating and sharing of reports using Azure Function, Blob Storage, Microsoft Flow and SharePoint

With Azure Functions, creating background jobs has become much easier. Azure Function provides different types of triggers like HTTP, Timer, Event Grid ETC. with a variety of input and output bindings like Blob storage, Cosmos DB, Webhook, SendGrid, ETC. as explained further in Azure Functions Triggers and Binding. I had a scenario where I had to generate a weekly report and store the data in an excel file format in a centralized location and we wanted to send an email notification when the file was uploaded.

Continue reading

Configuring continuous deployment of a hugo static site from Bitbucket onto Azure Web App with separate dev and production instances

If you don’t know already, this blog (and the whole KhoslaTech.com website) is built using awesome static site generation tool Hugo. After working out the initial version of the site, we have set up following workflow within the team to make any change (generally) to the site (including a new blog post): The source code is hosted on Bitbucket private repository with two main branches Master and Development. Any change requires the developer to create a new branch off Development, make the change, get it peer-reviewed and merged into Development.

Continue reading

Unit testing Xamarin portable libraries

When there is a code or feature change, it’s always very difficult to manually or even automatically test a cross-platform application. Either we don’t have enough time to test it manually or running all your automated UI tests in a variety of devices is very costly in terms of money & time. It’s a good idea to break platform-independent codes into multiple smaller portable libraries and unit test them separately. We don’t necessarily have to run UI tests to verify the changes in a portable library.

Continue reading

Auto generate API documentation

When creating API for consumption by third party developers it is always important to document them. The task of creating API documentation may not be trivial but its fairly doable considering the tools available but the task of maintaining them seems to where the product teams fall short more often than not. All seems perfect at the launch of version 1 of the API with neat and clear documentation complementing the efficient API’s that you have so arduously built.

Continue reading

How to store null key in Generic Dictionary<TKey, TValue>

I was writing a cache optimized permit manager in ASPSecurityKit that stores entityIds as keys and list of permissions as values to reduce session size stored in Redis by 90%. In tests, I was using Nullable Guid? as the key type and it failed spectacularly with this exception: System.ArgumentNullException : Value cannot be null. Parameter name: key Researching about it, I stumbled on this SO question and this MSDN spec for Dictionary<TKey, TValue>.

Continue reading