Beispiel #1
0
        public void RegisterService(HttpListenerHost appHost, Type serviceType)
        {
            var processedReqs = new HashSet <Type>();

            var actions = ServiceExecGeneral.Reset(serviceType);

            foreach (var mi in serviceType.GetActions())
            {
                var requestType = mi.GetParameters()[0].ParameterType;
                if (processedReqs.Contains(requestType))
                {
                    continue;
                }
                processedReqs.Add(requestType);

                ServiceExecGeneral.CreateServiceRunnersFor(requestType, actions);

                //var returnMarker = GetTypeWithGenericTypeDefinitionOf(requestType, typeof(IReturn<>));
                //var responseType = returnMarker != null ?
                //      GetGenericArguments(returnMarker)[0]
                //    : mi.ReturnType != typeof(object) && mi.ReturnType != typeof(void) ?
                //      mi.ReturnType
                //    : Type.GetType(requestType.FullName + "Response");

                RegisterRestPaths(appHost, requestType);

                appHost.AddServiceInfo(serviceType, requestType);
            }
        }
Beispiel #2
0
        public Task <object> Execute(HttpListenerHost appHost, object requestDto, IRequest req)
        {
            req.Dto = requestDto;
            var requestType = requestDto.GetType();

            req.OperationName = requestType.Name;

            var serviceType = appHost.GetServiceTypeByRequest(requestType);

            var service = appHost.CreateInstance(serviceType);

            //var service = typeFactory.CreateInstance(serviceType);

            var serviceRequiresContext = service as IRequiresRequest;

            if (serviceRequiresContext != null)
            {
                serviceRequiresContext.Request = req;
            }

            if (req.Dto == null) // Don't override existing batched DTO[]
            {
                req.Dto = requestDto;
            }

            //Executes the service and returns the result
            return(ServiceExecGeneral.Execute(serviceType, req, service, requestDto, requestType.GetMethodName()));
        }
Beispiel #3
0
        public Task <object> Execute(HttpListenerHost httpHost, object requestDto, IRequest req)
        {
            var requestType = requestDto.GetType();

            req.OperationName = requestType.Name;

            var serviceType = httpHost.GetServiceTypeByRequest(requestType);

            var service = httpHost.CreateInstance(serviceType);

            if (service is IRequiresRequest serviceRequiresContext)
            {
                serviceRequiresContext.Request = req;
            }

            // Executes the service and returns the result
            return(ServiceExecGeneral.Execute(serviceType, req, service, requestDto, requestType.GetMethodName()));
        }
        public void RegisterService(HttpListenerHost appHost, Type serviceType)
        {
            // Make sure the provided type implements IService
            if (!typeof(IService).IsAssignableFrom(serviceType))
            {
                _logger.LogWarning("Tried to register a service that does not implement IService: {ServiceType}", serviceType);
                return;
            }

            var processedReqs = new HashSet <Type>();

            var actions = ServiceExecGeneral.Reset(serviceType);

            foreach (var mi in serviceType.GetActions())
            {
                var requestType = mi.GetParameters()[0].ParameterType;
                if (processedReqs.Contains(requestType))
                {
                    continue;
                }

                processedReqs.Add(requestType);

                ServiceExecGeneral.CreateServiceRunnersFor(requestType, actions);

                //var returnMarker = GetTypeWithGenericTypeDefinitionOf(requestType, typeof(IReturn<>));
                //var responseType = returnMarker != null ?
                //      GetGenericArguments(returnMarker)[0]
                //    : mi.ReturnType != typeof(object) && mi.ReturnType != typeof(void) ?
                //      mi.ReturnType
                //    : Type.GetType(requestType.FullName + "Response");

                RegisterRestPaths(appHost, requestType, serviceType);

                appHost.AddServiceInfo(serviceType, requestType);
            }
        }