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 static class DomainEvents | |
{ | |
[ThreadStatic] //so that each thread has its own callbacks | |
private static List<Delegate> actions; | |
public static IContainer Container { get; set; } //as before | |
//Registers a callback for the given domain event | |
public static void Register<T>(Action<T> callback) where T : IDomainEvent | |
{ |
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 NoCacheAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) | |
{ | |
base.OnActionExecuted(actionExecutedContext); | |
if (actionExecutedContext.Response.IsSuccessStatusCode) | |
{ | |
var cc = new System.Net.Http.Headers.CacheControlHeaderValue(); | |
cc.NoStore = true; | |
cc.NoCache = true; |
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
protected RedirectToRouteResult RedirectToAction<T>(Expression<Action<T>> action, RouteValueDictionary values) where T : Controller | |
{ | |
var body = action.Body as MethodCallExpression; | |
if (body == null) | |
{ | |
throw new ArgumentException("Expression must be a method call."); | |
} | |
if (body.Object != action.Parameters[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
public class AutoMoqWebApiDataAttribute : AutoDataAttribute | |
{ | |
public AutoMoqWebApiDataAttribute() | |
: base(new Fixture().Customize(new AutoMoqWebApiCustomization())) | |
{ | |
} | |
} | |
public class AutoMoqWebApiCustomization : CompositeCustomization | |
{ |
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
using System; | |
using System.linq; | |
using System.collections.generic; | |
using System.IO; | |
using System.web.mvc; | |
namespace Securitymodule | |
{ | |
[Attributeusage (Attributetargets.method, Allowmultiple = false )] | |
public sealed class Allowuploadsafefilesattribute: Actionfilterattribute |
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 MethodOverrideHandler : DelegatingHandler | |
{ | |
readonly string[] _methods = { "DELETE", "HEAD", "PUT" }; | |
const string _header = "X-HTTP-Method-Override"; | |
protected override Task<HttpResponseMessage> SendAsync( | |
HttpRequestMessage request, CancellationToken cancellationToken) | |
{ | |
// Check for HTTP POST with the X-HTTP-Method-Override header. | |
if (request.Method == HttpMethod.Post && request.Headers.Contains(_header)) |
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
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)] | |
public sealed class ValidateAntiForgeryTokenAttribute : FilterAttribute, IAuthorizationFilter | |
{ | |
public Task<HttpResponseMessage> ExecuteAuthorizationFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func<Task<HttpResponseMessage>> continuation) | |
{ | |
try | |
{ | |
//could add optional ajax header check here | |
AntiForgery.Validate(); | |
} |
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 Email : IDisposable | |
{ | |
private SmtpClient _client; | |
private bool? _useSsl; | |
private Email() | |
{ | |
Message = new MailMessage(); | |
_client = new SmtpClient(); | |
} |
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 ApplicationManagement : IApplicationManagement | |
{ | |
private readonly IEnumerable<IApplicationSetting> _settings; | |
public ApplicationManagement(IEnumerable<IApplicationSetting> settings) | |
{ | |
_settings = settings; | |
try | |
{ |