Format:
Recent snippets for: Glenn Block
[InheritedExport] public interface ICompositionRoot { void Compose() } public class Bootstrapper : IDisposable { private CompositionContainer _container; public Composer(CompositionContainer container) { }
280 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.
169 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(),
231 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();
167 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>
80 Views
no comments
public class ForceJsonHandler : DelegatingHandler
{
public ForceJsonHandler(HttpMessageHandler innerHandler) : base(innerHandler)
{
}
protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
if (ShouldForceJson(request))
{
502 Views
3 comments
[ServiceContract] public class ContactResource { IContactRepository repository; public ContactResource(IContactRepository repository) { this.repository = repository; }
240 Views
no comments
public class MyConfig : HttpHostConfiguration { public HttpHostConfiguration { SetRequestOperationHandlers(new myHandler()); SetResponsOperationHandlers(new anotherHandler()); } }
189 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()
243 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; }
144 Views
no comments
public interface IRequestFactory { IRequest Create(Stream body); } public class RequestFactory : IRequestFactory { public IRequest Create(Stream body) { var wcfRequest = WebOperationContext.Current.IncomingRequest;
379 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) {
354 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(); }
353 Views
no comments
public class OrderMediaTypeProcessor : MediaTypeProcessor { public OrderMediaTypeProcessor(HttpOperationDescription operation, MediaTypeProcessorMode mode) :base(operation, mode) { } public override IEnumerable<string> SupportedMediaTypes {
374 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());
489 Views
7 comments
public interface IEntityTag { string EntityTag {get;} } public class TypedETagResponseProcessor : Processor<object,HttpResponseMessage, object> { private static ConcurrentDictionary<Uri, string> etags;
233 Views
2 comments
// Generates ETags automatically based on the return value. public interface IEntityTag { string EntityTag {get;} } public class ETagResponseProcessor : Processor { private ProcessorArgument returnValue;
362 Views
5 comments
// We're introducing a new request / response pipeline for allowing a composable model for processing the request/response. // Each processor takes inputs and outputs. Those outputs can be the HttpRequest (we have new strongly typed apis for this), HttpResponse, // Uri, Headers, or other outputs coming from processors before it. // This allows processors to feed into one another values, thus allowing composition of the handling. // These values also flow to the final operation thus you can transform components of the message / uri / headers into CLR objects, or even dynamic. // Below is a preview of how this will work.
918 Views
no comments
//This approach inspired by the EA approach Jeremy D Miller uses in StoryTeller. public class EventAggregator : IEventAggregator { private Dictionary<Type, List<WeakReference>> _eventSubscriberLists = new Dictionary<Type, List<WeakReference>>(); private object _lock = new object(); public void Subscribe(object subscriber) {
1204 Views
6 comments
/* some simple helpers to clean up the syntax / remove the need for the Get<Event> pattern. Works with pure poco event classes. Inspired by this post from Ward Bell: http://neverindoubtnet.blogspot.com/2009/07/simplify-prism-event-aggregator.html example usage given an OrderCreated event //Given this event: public class OrderCreated{ public Order Order {get;set;}
1739 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
