InstanceBehavior.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.ServiceModel;
  5. using System.ServiceModel.Dispatcher;
  6. using System.ServiceModel.Channels;
  7. using System.Text;
  8. namespace System.ServiceModel.Dispatcher
  9. {
  10. internal class InstanceBehavior
  11. {
  12. DispatchRuntime dispatch_runtime;
  13. internal InstanceBehavior (DispatchRuntime runtime) {
  14. dispatch_runtime = runtime;
  15. }
  16. internal void Initialize (InstanceContext iCtx) {
  17. Message message = OperationContext.Current.IncomingMessage;
  18. IContextChannel channel = OperationContext.Current.Channel;
  19. if (dispatch_runtime.InstanceContextProvider != null) {
  20. dispatch_runtime.InstanceContextProvider.InitializeInstanceContext (iCtx,
  21. message,
  22. channel);
  23. }
  24. foreach (IInstanceContextInitializer init in dispatch_runtime.InstanceContextInitializers)
  25. init.Initialize (iCtx, message);
  26. }
  27. internal object GetServiceInstance (InstanceContext ctx, Message m, ref bool createdByUserProvider) {
  28. if (dispatch_runtime.InstanceProvider != null) {
  29. createdByUserProvider = true;
  30. return dispatch_runtime.InstanceProvider.GetInstance (ctx, m);
  31. }
  32. createdByUserProvider = false;
  33. return Activator.CreateInstance (
  34. dispatch_runtime.ChannelDispatcher.Host.Description.ServiceType, true);
  35. }
  36. internal IInstanceContextProvider InstanceContextProvider {
  37. get {
  38. return dispatch_runtime.InstanceContextProvider;
  39. }
  40. }
  41. internal void ReleaseServiceInstance (InstanceContext ctx, object impl)
  42. {
  43. if (ctx.IsUserProvidedInstance) {
  44. dispatch_runtime.InstanceProvider.ReleaseInstance (ctx, impl);
  45. }
  46. }
  47. }
  48. }