CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets for: Glenn Block
C#
[InheritedExport]
public interface ICompositionRoot {
  void Compose() 
}
 
public class Bootstrapper : IDisposable {
  private CompositionContainer _container;
 
  public Composer(CompositionContainer container) {
  }
by Glenn Block   October 15, 2011 @ 10:53am
Tags:
280 Views
no comments
 
C#
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.
by Glenn Block   August 30, 2011 @ 10:47pm
Tags:
169 Views
no comments
 
C#
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(),
by Glenn Block   August 30, 2011 @ 10:43pm
Tags:
231 Views
no comments
 
C#
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();
by Glenn Block   August 04, 2011 @ 11:17am
Tags:
167 Views
no comments
 
C#
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>
by Glenn Block   August 01, 2011 @ 2:34pm
Tags:
80 Views
no comments
 
C#
    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))
            {
by Glenn Block   July 11, 2011 @ 1:31am
Tags:
502 Views
3 comments
 
C#
[ServiceContract]
public class ContactResource
{
    IContactRepository repository;
 
    public ContactResource(IContactRepository repository)
    {
        this.repository = repository;
    }
by Glenn Block   May 26, 2011 @ 1:21pm
Tags:
240 Views
no comments
 
C#
public class MyConfig : HttpHostConfiguration {
  public HttpHostConfiguration
  {
    SetRequestOperationHandlers(new myHandler());
    SetResponsOperationHandlers(new anotherHandler());
  }
}
by Glenn Block   March 31, 2011 @ 10:31am
Tags:
189 Views
no comments
 
C#
var builder = HttpHostConfiguration.Create().
    RequestHandlers.
      Add(new SpecialRequestHandler()).
      Add(new AnotherRequestHandler()).
      When((o,s)=>o.Name.StartsWith("Foo")
    ResponseHanders.
      Add(new GlobalRequestHandler()).
      Always()
 
by Glenn Block   March 31, 2011 @ 10:23am
Tags:
243 Views
2 comments
 
C#
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;
    }
 
by Glenn Block   March 07, 2011 @ 4:58am
Tags:
144 Views
no comments
 
C#
public interface IRequestFactory
{
    IRequest Create(Stream body);
}
 
public class RequestFactory : IRequestFactory
{
    public IRequest Create(Stream body)
    {
        var wcfRequest = WebOperationContext.Current.IncomingRequest;
by Glenn Block   December 17, 2010 @ 1:07am
Tags:
379 Views
no comments
 
C#
[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)
    {
by Glenn Block   December 17, 2010 @ 1:02am
Tags:
354 Views
no comments
 
C#
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();
    }
by Glenn Block   December 16, 2010 @ 12:00am
Tags:
353 Views
no comments
 
C#
public class OrderMediaTypeProcessor : MediaTypeProcessor
{
    public OrderMediaTypeProcessor(HttpOperationDescription operation, MediaTypeProcessorMode mode)
        :base(operation, mode)
    {
        
    }
 
    public override IEnumerable<string> SupportedMediaTypes
    {
by Glenn Block   November 11, 2010 @ 1:53am
Tags:
374 Views
no comments
 
C#
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());
by Glenn Block   November 10, 2010 @ 7:39am
Tags: WCF
489 Views
7 comments
 
C#
public interface IEntityTag
{
    string EntityTag {get;}
}
 
public class TypedETagResponseProcessor : Processor<object,HttpResponseMessage, object>
{
 
    private static ConcurrentDictionary<Uri, string> etags;
by Glenn Block   November 03, 2010 @ 12:01am
Tags:
233 Views
2 comments
 
C#
// Generates ETags automatically based on the return value.
 
public interface IEntityTag
{
    string EntityTag {get;}
}
 
public class ETagResponseProcessor : Processor
{
    private ProcessorArgument returnValue;
by Glenn Block   November 02, 2010 @ 4:44pm
Tags:
362 Views
5 comments
 
C#
// 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.
 
 
by Glenn Block   October 21, 2010 @ 2:28am
Tags:
918 Views
no comments
 
C#
//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)
    {
by Glenn Block   October 18, 2010 @ 2:15am
Tags:
1204 Views
6 comments
 
C#
/*
  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;}
by Glenn Block   October 10, 2010 @ 9:20pm
1739 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate