示例#1
0
        /// <summary>
        /// Creates a <typeparamref name="TDomainService"/> proxy instance that implements
        /// <typeparamref name="TDomainServiceContract"/>.
        /// </summary>
        /// <typeparam name="TDomainServiceContract">The <see cref="DomainService"/> contract interface.</typeparam>
        /// <typeparam name="TDomainService">The <see cref="DomainService"/> type that implements <typeparamref name="TDomainServiceContract"/>.</typeparam>
        /// <param name="httpContext">The <see cref="HttpContextBase"/> instance that should be provided to <typeparamref name="TDomainService"/>
        /// proxy instances.</param>
        /// <returns>Returns a <typeparamref name="TDomainService"/> proxy instance that implements
        /// <typeparamref name="TDomainServiceContract"/>.</returns>
        public static TDomainServiceContract Create <TDomainServiceContract, TDomainService>(HttpContextBase httpContext)
            where TDomainServiceContract : IDisposable
            where TDomainService : DomainService
        {
            // Create a DomainServiceContext (with access to the provided HttpContextBase) and use that as our context
            HttpContextBaseServiceProvider serviceProvider = new HttpContextBaseServiceProvider(httpContext);
            DomainServiceContext           context         = new DomainServiceContext(serviceProvider, DomainOperationType.Query);

            return(DomainServiceProxy.Create <TDomainServiceContract, TDomainService>(context));
        }
示例#2
0
        /// <summary>
        /// Creates a <typeparamref name="TDomainService"/> proxy instance that implements
        /// <typeparamref name="TDomainServiceContract"/>.
        /// </summary>
        /// <typeparam name="TDomainServiceContract">The <see cref="DomainService"/> contract interface.</typeparam>
        /// <typeparam name="TDomainService">The <see cref="DomainService"/> type that implements <typeparamref name="TDomainServiceContract"/>.</typeparam>
        /// <param name="domainServiceContext">The <see cref="DomainServiceContext"/> instance that should be provided to <typeparamref name="TDomainService"/>
        /// proxy instances.</param>
        /// <returns>Returns a <typeparamref name="TDomainService"/> proxy instance that implements
        /// <typeparamref name="TDomainServiceContract"/>.</returns>
        public static TDomainServiceContract Create <TDomainServiceContract, TDomainService>(DomainServiceContext domainServiceContext)
            where TDomainServiceContract : IDisposable
            where TDomainService : DomainService
        {
            if (domainServiceContext == null)
            {
                throw new ArgumentNullException("domainServiceContext");
            }

            // Get or create the proxy type
            Type proxyType = DomainServiceProxy.GetProxyType <TDomainServiceContract, TDomainService>();

            // Instantiate and initialize it.  Here, we have intrinsic knowledge about our proxy instance
            // in that the proxy generator will implement IDomainServiceProxy as well.
            TDomainServiceContract proxyInstance = (TDomainServiceContract)Activator.CreateInstance(proxyType);
            MethodInfo             initMethod    = proxyType.GetMethod("Initialize", BindingFlags.Public | BindingFlags.Instance);

            initMethod.Invoke(proxyInstance, new object[] { typeof(TDomainService), domainServiceContext });

            return(proxyInstance);
        }