Format:
Recent snippets for: Glenn Block
using System; using System.Collections; using System.Collections.Generic; using System.Json; using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Formatting; using System.Net.Http.Headers; using System.Web;
237 Views
no comments
[TestClass] public class RavenDbRepositoryTests { private RavenDbRepository repo; private const string collectionName = "tests"; private const string serverUri = "http://localhost:8080"; private FakeHandler handler; [TestInitialize]
53 Views
no comments
public class FakeHandler : System.Net.Http.DelegatingHandler { public HttpRequestMessage LastRequest { get; set; } public HttpResponseMessage Response { get; set; } protected override System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { LastRequest = request; if (Response == null) Response = base.Send(request, cancellationToken);
182 Views
no comments
[InheritedExport] public interface ICompositionRoot { void Compose() } public class Bootstrapper : IDisposable { private CompositionContainer _container; public Composer(CompositionContainer container) { }
355 Views
no comments
public class MefConfiguration : HttpConfiguration { public MefConfiguration(CompositionContainer container) { SetServiceInstanceProvider((t, i, m) => { var contract = AttributedModelServices.GetContractName(t); var identity = AttributedModelServices.GetTypeIdentity(t); // force non-shared so that every service doesn't need to have a [PartCreationPolicy] attribute.
194 Views
no comments
protected void Application_Start(object sender, EventArgs e) { // use MEF for providing instances var catalog = new AssemblyCatalog(typeof(Global).Assembly); var container = new CompositionContainer(catalog); var config = new MefConfiguration(container); RouteTable.Routes.SetDefaultHttpConfiguration(config); config.Formatters.AddRange( new ContactPngFormatter(),
265 Views
no comments
public class ETagHandler : DelegatingHandler { internal static ConcurrentDictionary<string, EntityTagHeaderValue> ETagCache = new ConcurrentDictionary<string, EntityTagHeaderValue>(); protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { if (request.Method == HttpMethod.Get) { // should we ignore trailing slash string resource = request.RequestUri.ToString();
272 Views
no comments
public class static XamlComposer { public static void SetComposer(ICompositionRootComposer composer){ } public static void Compose<T>(ICompositionRoot<T> root) { //resolve T from the container and set root.Component. } } public class AuditBehavior : DependencyObject, ICompositionRoot<AuditBehaviorComponent>
100 Views
no comments
public class ForceJsonHandler : DelegatingHandler
{
protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
if (ShouldForceJson(request))
{
request.Headers.Accept.Clear(); //clear the accept and replace it to use JSON.
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
return base.SendAsync(request, cancellationToken);
761 Views
3 comments
[ServiceContract] public class ContactResource { IContactRepository repository; public ContactResource(IContactRepository repository) { this.repository = repository; }
280 Views
no comments
public class MyConfig : HttpHostConfiguration { public HttpHostConfiguration { SetRequestOperationHandlers(new myHandler()); SetResponsOperationHandlers(new anotherHandler()); } }
214 Views
no comments
var builder = HttpHostConfiguration.Create(). RequestHandlers. Add(new SpecialRequestHandler()). Add(new AnotherRequestHandler()). When((o,s)=>o.Name.StartsWith("Foo") ResponseHanders. Add(new GlobalRequestHandler()). Always()
265 Views
2 comments
public class UriExtensionProcessor : Processor<HttpRequestMessage,Uri> { private IEnumerable<Tuple<string,string>> extensionMappings; public UriExtensionProcessor(IEnumerable<Tuple<string, string>> extensionMappings) { this.extensionMappings = extensionMappings; this.OutArguments[0].Name = HttpPipelineFormatter.ArgumentUri; }
180 Views
no comments
public interface IRequestFactory { IRequest Create(Stream body); } public class RequestFactory : IRequestFactory { public IRequest Create(Stream body) { var wcfRequest = WebOperationContext.Current.IncomingRequest;
470 Views
no comments
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] [ServiceContract] public class WcfOwinHost { private IApplication _application; private IRequestFactory _requestFactory; private IResponseMessageFactory _responseFactory; public WcfApplication(IApplication application, IRequestFactory requestFactory, IResponseMessageFactory responseFactory) {
400 Views
no comments
class Program { static void Main(string[] args) { var host = new WebServiceHost(typeof (Application), new Uri("http://localhost")); host.Open(); Console.WriteLine("Server is running"); Console.ReadLine(); host.Close(); }
390 Views
no comments
public class OrderMediaTypeProcessor : MediaTypeProcessor { public OrderMediaTypeProcessor(HttpOperationDescription operation, MediaTypeProcessorMode mode) :base(operation, mode) { } public override IEnumerable<string> SupportedMediaTypes {
444 Views
no comments
public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { var builder = new ContainerBuilder(); builder.RegisterType<ContactResource>(); builder.RegisterType<ContactsResource>(); builder.RegisterType<ContactRepository>().As<IContactRepository>(); var configuration = new ContactManagerConfiguration(builder.Build());
538 Views
7 comments
public interface IEntityTag { string EntityTag {get;} } public class TypedETagResponseProcessor : Processor<object,HttpResponseMessage, object> { private static ConcurrentDictionary<Uri, string> etags;
253 Views
2 comments
// Generates ETags automatically based on the return value. public interface IEntityTag { string EntityTag {get;} } public class ETagResponseProcessor : Processor { private ProcessorArgument returnValue;
400 Views
5 comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
