This post discusses a Snapshot manager that I wrote which takes a snapshot of each of my changes by storing entries, and also allows me to backward and forward my changes with DbContext.
- UndoRedoPOC.zip
- UndoRedoPOC
- ConsoleClient
- Lib.DataAccess
- Lib.Global
- Lib.Model
- Library
- EntityFramework.dll
- LogicService.Contract
- LogicService
- packages
- EntityFramework.5.0.0
- Content
- App.config.transform
- Web.config.transform
- EntityFramework.5.0.0.nupkg
- lib
- net40
- net45
- tools
- repositories.config
- UndoRedoPOC.sln
- UndoRedoPOC.suo
- UndoRedoPOC.v11.suo
- UndoRedoPOC-noexe.zip
|
using System;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace Lib.Global
{
public sealed class ComposableBehavior : BehaviorExtensionElement
{
public override Type BehaviorType
{
get { return typeof(ComposableBehaviorAttribute); }
}
protected override object CreateBehavior()
{
return new ComposableBehaviorAttribute();
}
}
[AttributeUsage(AttributeTargets.Class)]
public sealed class ComposableBehaviorAttribute : Attribute, IServiceBehavior
{
#region IServiceBehavior Members
void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
// Retrieve service type:
var serviceType = serviceHostBase.Description.ServiceType;
// Install ComposingInstanceProvider on each endpoint:
foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
{
foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
{
endpointDispatcher.DispatchRuntime.InstanceProvider = new ComposingInstanceProvider(serviceType);
}
}
}
void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
#endregion
}
public class ComposingInstanceProvider : IInstanceProvider
{
private Type serviceType;
public ComposingInstanceProvider(Type serviceType)
{
this.serviceType = serviceType;
}
public object GetInstance(System.ServiceModel.InstanceContext instanceContext)
{
return this.GetInstance(instanceContext, null);
}
public object GetInstance(System.ServiceModel.InstanceContext instanceContext, System.ServiceModel.Channels.Message message)
{
// Create composer:
var composer = new ServiceComposer();
instanceContext.Extensions.Add(composer);
// Retrieve instance:
var instance = Activator.CreateInstance(this.serviceType);
// Compose instance:
composer.Compose(instance);
// Return instance:
return instance;
}
public void ReleaseInstance(System.ServiceModel.InstanceContext instanceContext, object instance)
{
// Remove composer:
var composer = instanceContext.Extensions.Find<ServiceComposer>();
if (composer != null)
instanceContext.Extensions.Remove(composer);
// Release instance:
if (instance is IDisposable)
((IDisposable)instance).Dispose();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
In my childhood, my uncle has shown me how to see the cloud in a close look and I understand that one can draw some elements of the Earth in the sky-canvas if he/she wants to. After that the cloud becomes closer to me and It teaches me one thing that, a deeper-look to something will give you some clues to draw your imagination. You can able to see that one which you have build-up in your mind.
Years past, I have started my career as a software engineer and has been looking for passion in my coding and development which I should be to enjoy my profession and has started asking myself- 'am I doing any engineering here?!' Is my code becoming that thing which I have designed in my mind? So to find that answer I have tried that old solution here... I have decided to come closer to my code and start analyzing them. And it is really working for me and at least it gives me the confidence that I can build something that I really want to. I can draw my thinking there through my code and can build-up my vision that I have designed in my mind. It also helps me to think out of the box, solve each problems by making blocks and make me careful on each steps.
• Morshed's Technical Blog site: http://morshedanwar.wordpress.com/
• Morshed's Technical articles those are published in Codeproject site: http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=2992452
• Morshed's Linkedin profile: http://www.linkedin.com/in/morshedanwar
• Morshed's Facebook Profile : http://www.facebook.com/morshed.pulok
Beside all these I like to do - photography and music. Here is my Flickr photos : http://www.flickr.com/photos/morshed_anwar/