internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime) { this.useSession = dispatch.ChannelDispatcher.Session; this.immutableRuntime = immutableRuntime; this.host = (dispatch.ChannelDispatcher == null) ? null : dispatch.ChannelDispatcher.Host; this.initializers = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers); this.provider = dispatch.InstanceProvider; this.singleton = dispatch.SingletonInstanceContext; this.transactionAutoCompleteOnSessionClose = dispatch.TransactionAutoCompleteOnSessionClose; this.releaseServiceInstanceOnTransactionComplete = dispatch.ReleaseServiceInstanceOnTransactionComplete; this.isSynchronized = (dispatch.ConcurrencyMode != ConcurrencyMode.Multiple); this.instanceContextProvider = dispatch.InstanceContextProvider; if (this.provider == null) { ConstructorInfo constructor = null; if (dispatch.Type != null) { constructor = InstanceBehavior.GetConstructor(dispatch.Type); } if (this.singleton == null) { if (dispatch.Type != null && (dispatch.Type.IsAbstract || dispatch.Type.IsInterface)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxServiceTypeNotCreatable))); } if (constructor == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoDefaultConstructor))); } } if (constructor != null) { if (this.singleton == null || !this.singleton.IsWellKnown) { InvokerUtil util = new InvokerUtil(); CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor); this.provider = new InstanceProvider(creator); } } } if (this.singleton != null) { this.singleton.Behavior = this; } }