Created
November 15, 2011 05:20
-
-
Save JoshClose/1366231 to your computer and use it in GitHub Desktop.
Setting Up WCF with Multiple Services and Multiple Databases Using NHibernate and Ninject 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ServiceModel.Configuration; | |
namespace Wnn.Service.Host | |
{ | |
public class NHibernateBehaviorExtensionElement : BehaviorExtensionElement | |
{ | |
protected override object CreateBehavior() | |
{ | |
return new NHibernateServiceBehavior(); | |
} | |
public override Type BehaviorType | |
{ | |
get { return typeof( NHibernateServiceBehavior ); } | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.ObjectModel; | |
using System.ServiceModel; | |
using System.ServiceModel.Channels; | |
using System.ServiceModel.Description; | |
using System.ServiceModel.Dispatcher; | |
namespace Wnn.Service.Host | |
{ | |
public class NHibernateServiceBehavior : Attribute, IServiceBehavior | |
{ | |
public void Validate( ServiceDescription serviceDescription, ServiceHostBase serviceHostBase ) | |
{ | |
} | |
public void AddBindingParameters( ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters ) | |
{ | |
} | |
public void ApplyDispatchBehavior( ServiceDescription serviceDescription, ServiceHostBase serviceHostBase ) | |
{ | |
foreach( var channelDispatcherBase in serviceHostBase.ChannelDispatchers ) | |
{ | |
var channelDispatcher = channelDispatcherBase as ChannelDispatcher; | |
if( channelDispatcher == null ) | |
{ | |
continue; | |
} | |
foreach( var ed in channelDispatcher.Endpoints ) | |
{ | |
ed.DispatchRuntime.InstanceProvider = new NHibernateInstanceProvider( serviceDescription.ServiceType ); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Wnn.Service.Host.Console | |
{ | |
class Program | |
{ | |
static void Main( string[] args ) | |
{ | |
var service = new ServiceHostEngine(); | |
service.Start(); | |
System.Console.WriteLine( "Press any key to stop the services" ); | |
System.Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment