Esempio n. 1
0
            public void Setup(string baseAddress, MethodInfo config, Type traceWriterType, string defaultRouteTemplate)
            {
                var configuration = new HttpSelfHostConfiguration(baseAddress);

                // default map
                // TODO: centralize default route mapping in all host strategies
                configuration.Routes.MapHttpRoute(
                    "api default", defaultRouteTemplate, new { action = RouteParameter.Optional });

                // TODO: Add a sample educating user how to communicate to Tracer under partial trust.
                if (traceWriterType != null)
                {
                    /// TODO: improvement
                    /// There are other ways of initializing a trace writer, for example you can pass in
                    /// a factory method or an already-created instance.
                    configuration.Services.Replace(typeof(ITraceWriter), Activator.CreateInstance(traceWriterType));
                }

                _server = new HttpSelfHostServer(configuration);
                configuration.SetHttpServer(_server);

                if (config != null)
                {
                    config.Invoke(null, new object[] { configuration });
                }

                _server.OpenAsync().Wait();
            }