Skip to content

Instantly share code, notes, and snippets.

View ngohungphuc's full-sized avatar
🏡
Sài Gòn & Lelystad

Tony Ngo ngohungphuc

🏡
Sài Gòn & Lelystad
View GitHub Profile
@rmacfie
rmacfie / MediatRExtensions.cs
Last active June 23, 2024 01:18
Register MediatR handlers in Asp.Net 5 / vNext / Core
namespace Microsoft.AspNet.Builder
{
public static class MediatRExtensions
{
public static IServiceCollection AddMediatR(this IServiceCollection services, params Assembly[] handlerAssemblies)
{
services.AddTransient<IMediator>(x => new Mediator(x.GetService<SingleInstanceFactory>(), x.GetService<MultiInstanceFactory>()));
services.AddTransient<SingleInstanceFactory>(x => t => x.GetRequiredService(t));
services.AddTransient<MultiInstanceFactory>(x => t => x.GetServices(t));
@maartenba
maartenba / DomainTemplateRoute - GetVirtualPath
Last active May 15, 2023 07:30
ASP.NET MVC 6 / ASP.NET 5 Domain Routing + Tenant Middleware
public string GetVirtualPath(VirtualPathContext context)
{
foreach (var matcherParameter in _matcher.Template.Parameters)
{
context.Values.Remove(matcherParameter.Name); // make sure none of the domain-placeholders are appended as query string parameters
}
return _innerRoute.GetVirtualPath(context);
}
@andygjp
andygjp / ReplaceNullContentWithNotFoundAttribute
Created October 15, 2014 21:58
A workaround that will recognise when a SingleResult type does not contain any results and replace it with a 404 instead of throwing a SerializationException.
internal class ReplaceNullContentWithNotFoundAttribute : EnableQueryAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
base.OnActionExecuted(actionExecutedContext);
HttpResponseMessage httpResponseMessage = actionExecutedContext.Response;
if (httpResponseMessage.IsSuccessStatusCode && IsContentMissingValue(httpResponseMessage))
{
actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(HttpStatusCode.NotFound);
@imranismail
imranismail / autocomplete.php
Last active April 4, 2024 13:15
Laravel And JqueryUI's Autocomplete Plugin
//SearchController.php
public function autocomplete(){
$term = Input::get('term');
$results = array();
$queries = DB::table('users')
->where('first_name', 'LIKE', '%'.$term.'%')
->orWhere('last_name', 'LIKE', '%'.$term.'%')
->take(5)->get();