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#
public class UriBinder : HttpProcessor
{
    private static List<UriBinding> _bindings;
 
    static UriBinder()
    {
        _bindings = new List<UriBinding>();
    }
 
    public static void AddUriBinding<TModel>(string name, string matchRegex, Func<int, object> modelFactory)
by Glenn Block   Wednesday @ 1:19am
Tags:
43 Views
no comments
 
C#
//in startup
UriBinder.AddUriBinding<Contact>("contact", "contact/(.+)", 
    cid => ContactsHandler._contacts.Single(c => c.ContactID == cid));
 
//request is http://contactmanager/contact/1 
 
//the resource takes contact as a param
public class ContactHandler {
    public Contact Get(Contact contact)
    {
by Glenn Block   Wednesday @ 1:06am
Tags:
30 Views
no comments
 
C#
var config = ResourceConfiguration.Configure("ContactManager").
    Conventions(c =>
        {
            c.PostMethod(m => m.Name.StartsWith("Updated"));
            c.DeleteMethod(m => m.Name.StartsWith("Remove"));
            c.Uri<MyUriConvention>();
            c.Model<MyModelConvention>();
        }
    ).
    ResourceScanner<MyResourceScanner>().
by Glenn Block   August 22, 2010 @ 11:58pm
Tags:
43 Views
no comments
 
C#
var config = ResourceConfiguration.Configure("ContactManager").
    Conventions(c =>
        {
            c.Method("POST").To(m => m.Name.StartsWith("Updated"));
            c.Method("DELETE").To(m => m.Name.StartsWith("Remove"));
            c.Uri<MyUriConvention>();
            c.Model<MyModelConvention>();
        }
    ).
    ResourceScanner<MyResourceScanner>().
by Glenn Block   August 22, 2010 @ 11:31pm
Tags:
104 Views
no comments
 
C#
var config = ResourceConfiguration.Configure("ContactManager").
    Conventions(c =>
        {
            c.Method("POST").To(m => m.Name.StartsWith("Updated"));
            c.Method("DELETE").To(m => m.Name.StartsWith("Remove"));
            c.Uri(t => GetUriFromType(t));
            c.Model(t => GetModelFromResource(t));
        }
    ).
    ResourceScanner<MyResourceScanner>().
by Glenn Block   August 22, 2010 @ 11:03pm
Tags:
95 Views
no comments
 
C#
var config = ResourceConfiguration.Configure.
    Conventions(c=>
        {
            c.
                Method("Post").Convention(m => m.Name.StartsWith("Updated")).
                Method("Delete").Convention(m => m.Name.StartsWith("Remove")).
                UriConvention(t => GetUriFromType(t)).
                ModelConvention(t => GetModelFromResource(t));
        }
    ).
by Glenn Block   August 22, 2010 @ 12:52am
Tags:
66 Views
no comments
 
C#
ServiceHost.Create<EchoService>
  .Uri("http://MySite.com")
      .EndPoint<IEcho>
         .Address("...")
         .Binding<BasicHttpBinding>
by Glenn Block   August 12, 2010 @ 7:11pm
Tags:
162 Views
no comments
 
[HandleError]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewData["Message"] = "Welcome to ASP.NET MVC!";
 
        return View();
    }
by Glenn Block   July 11, 2010 @ 11:28pm
Tags:
65 Views
no comments
 
C#
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
// NOTE: If the service is renamed, remember to update the global.asax.cs file
public class MessageService
{
    [WebGet(UriTemplate = "/Method1?a={var1}&b={var2}")]
    [CompositeOperationBehavior("MessageService")]
    public Message GetMessage(string var1, string var2)
    {
by Glenn Block   July 02, 2010 @ 9:51pm
Tags:
123 Views
no comments
 
C#
routes.AddRoute<OrdersResource>("/Orders");
routes.AddRoute<OrdersResource>("/Orders/{Order}")
 
public class OrdersResource {
  //dependencies can be injected
  public OrdersResource(IRepository<Order> orderRepository) {
  }
 
  public JsonResponseMessage GetOrders() {}  // allows explict mapping for contentneg based on return value
  public XmlResponseMessage GetOrders() {}
by Glenn Block   June 26, 2010 @ 11:50am
Tags: REST
443 Views
no comments
 
C#
using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Primitives;
using System.ComponentModel.Composition.Hosting;
 
namespace Microsoft.ComponentModel.Composition
{
    public static class CompositionInitializerEx
    {
        public static void SatisfyImports(ComposablePart part, bool allowRecomposition = false)
by Glenn Block   June 02, 2010 @ 10:29pm
Tags:
168 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.Composition.Hosting;
 
namespace Given_two_order_view_models
{
by Glenn Block   May 28, 2010 @ 7:04pm
Tags:
201 Views
no comments
 
C#
 
public static class CatalogExtensions
{
    public static IEnumerable<Assembly> ToAssemblies(this ComposablePartCatalog catalog)
    {
        return catalog.Parts.Select(p => ((Type) ReflectionModelServices.GetPartType(p).Value).Assembly).Distinct();
    }
}
 
by Glenn Block   April 14, 2010 @ 1:28pm
Tags:
213 Views
no comments
 
C#
public static class ExportFactoryExtensions
{
    public static T GetInstance<T>(this ExportFactory<T> factory)
    {
        var export = factory.CreateExport();
        return export.Value;
    }
}
by Glenn Block   April 12, 2010 @ 10:10pm
Tags:
178 Views
no comments
 
C#
using System; 
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.Linq;
using System.Text;
 
public class ConfigurationExportProvider : ExportProvider
by Glenn Block   April 11, 2010 @ 11:47pm
Tags:
623 Views
1 comments
 
C#
[Export(typeof(IModuleManager))]
public class ModuleManager : IModuleManager
{
    [ImportMany]
    public IEnumerable<Lazy<IModule>> Modules { get; set; }
 
    public void Load()
    {
        foreach(var lazyModule in Modules)
        {
by Glenn Block   March 31, 2010 @ 11:09pm
Tags:
736 Views
1 comments
 
C#
public class StoryFrameEditorViewModel : ViewModel
{
    public StoryFrameEditorViewModel()
    {
        _template = Field<StoryFrameTemplate>("Template");
    }
    
    private BackingField<StoryFrameTemplate> _template; 
    public StoryFrameTemplate Template
    {
by Glenn Block   March 24, 2010 @ 2:41am
Tags:
319 Views
no comments
 
C#
#region $entity$
 
public IQueryable<$entity$> Get$entities$()
{
    return this.DataContext.$entities$;
}
 
public void Insert$entity$($entity$ current$entity$)
{
    this.DataContext.$entities$.InsertOnSubmit(current$entity$);
by Glenn Block   March 23, 2010 @ 11:39pm
Tags: RIA
289 Views
no comments
 
C#
[Export]
public class OrderView {
  [Import("OrderViewViewModel")]
  public object ViewModel {
    get{return this.DataContext;}
    set{this.DataContext = value;}
  }
}
 
[Export]
by Glenn Block   March 22, 2010 @ 11:27am
Tags:
323 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
 
namespace DynamicObjectContracts
{
    public class Program
by Glenn Block   March 17, 2010 @ 9:32am
Tags: Dynamic, MEF
324 Views
no comments
 
C#
public class ViewModelInitializer<TViewModel,TModel> where TViewModel : IViewModel<TModel>
{
    private Func<TViewModel> _viewModelFactory;
 
    public ViewModelInitializer(Func<TViewModel> viewModelFactory)
    {
        _viewModelFactory = viewModelFactory;
    }
 
    public void Initialize(FrameworkElement view, TModel model)
by Glenn Block   February 07, 2010 @ 3:07pm
Tags: MEF
292 Views
no comments
 
C#
// Below RecentlyUsedTrackerConfiguration provides configuration information through property exports. MEF pulls on the property getters and exports that info. 
// If the part needs to be data drvien, you can still access a service behind the scenes in the getter (or the constructor) to get the info.
 
public class RecentlyUsedTrackerConfiguration
{
  public RecentlyUsedTrackerConfiguration()
  {
     //set values here
  }
by Glenn Block   January 26, 2010 @ 6:34pm
Tags: MEF
273 Views
no comments
 
C#
public static class AsyncTestExtensions
{
    public static void EnqueueUntilLoaded(this SilverlightTest test, FrameworkElement element, params Action[] actions)
    {
        var isLoaded = false;
        element.Loaded += (s, e) => isLoaded = true;
        test.EnqueueConditional(() => isLoaded);
        test.EnqueueCallback(actions);
        test.EnqueueTestComplete();
    }
by Glenn Block   January 24, 2010 @ 12:29pm
Tags:
217 Views
no comments
 
C#
namespace System.ComponentModel.Composition.Hosting
{
    public class DeploymentCatalog : ComposablePartCatalog, INotifyComposablePartCatalogChanged
    {
        public DeploymentCatalog();
        public DeploymentCatalog(string uri);
        public DeploymentCatalog(Uri uri);
        public override IQueryable<ComposablePartDefinition> Parts { get; }
        public Uri Uri { get; }
by Glenn Block   January 22, 2010 @ 11:36am
Tags:
206 Views
no comments
 
C#
using System.ComponentModel.Composition;
using Microsoft.Practices.Composite.Events;
 
//this version uses a static backing field so that the instance is automatically shared across all containers.
public class EventAggregatorPart
{
    private static IEventAggregator _eventAggregator;
 
    static EventAggregatorPart()
    {   
by Glenn Block   January 10, 2010 @ 11:30pm
447 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