//Currently there are four pieces of middleware //IsDevelopment, CustomMiddleware, UseWelcomePage, Greetings // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IGreetings greetings, ILogger <Startup> logger) { //Middleware Configuration goes here //*** Sequence is important *** if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //To make sure that index.html is called as default file //we need to have this middleware in place //if this is not there then we need to call //sitename.com/index.html always this bypasses that // app.UseDefaultFiles(); //To call static pages we need this middleware //This loads pages from wwwroot folder // app.UseStaticFiles(); //replaces UseDefaultFiles and UseStaticFiles with one call app.UseFileServer(); //Get Current environment var environment = env.EnvironmentName; //Custom Middleware for path /mym i.e. my middleware :) //if url is not /mym then pass along // app.Use(next => { // return async context => { // logger.LogInformation("Request Incoming"); // if (context.Request.Path.StartsWithSegments("/mym")) // { // await context.Response.WriteAsync("Hit!!"); // logger.LogInformation("Response Handled"); // } // else // { // await next(context); // logger.LogInformation("Response Outgoing"); // } // }; // }); //Responds to request whose path would be /wp // app.UseWelcomePage(new WelcomePageOptions{ // Path = "/wp" // }); app.Run(async(context) => { // throw new Exception("Error"); var greeting = greetings.GetGreetings(); await context.Response.WriteAsync($"{greeting} : {environment}"); }); }
public void CallbackExample1() { //Start service and use net.tcp binding ServiceHost eventServiceHost = new ServiceHost(typeof(GreetingsService)); NetTcpBinding tcpBindingpublish = new NetTcpBinding(); tcpBindingpublish.Security.Mode = SecurityMode.None; eventServiceHost.AddServiceEndpoint(typeof(IGreetings), tcpBindingpublish, "net.tcp://localhost:8000/GreetingsService"); eventServiceHost.Open(); //Create client proxy NetTcpBinding clientBinding = new NetTcpBinding(); clientBinding.Security.Mode = SecurityMode.None; EndpointAddress ep = new EndpointAddress("net.tcp://localhost:8000/GreetingsService"); ClientCallback cb = new ClientCallback(); IGreetings proxy = DuplexChannelFactory <IGreetings> .CreateChannel(new InstanceContext (cb), clientBinding, ep); //Call service proxy.SendMessage(); //Wait for callback - sort of hack, but better than using wait handle to possibly block tests. Thread.Sleep(1000); //Cleanup eventServiceHost.Close(); Assert.IsTrue(CallbackSent, "#1"); Assert.IsTrue(CallbackReceived, "#1"); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IGreetings greetings, ILogger <StartupMvc> logger) { //*** Sequence is important *** if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //Get Current environment var environment = env.EnvironmentName; app.UseStaticFiles(); // app.UseMvcWithDefaultRoute(); app.UseMvc(ConfigureRoutes); app.Run(async(context) => { // throw new Exception("Error"); var greeting = greetings.GetGreetings(); context.Response.ContentType = "text/plain"; // await context.Response.WriteAsync($"{greeting} : {environment}"); await context.Response.WriteAsync($"Page Not Found"); }); }
public ActionResult Greet([FromServices] IGreetings greetingService) { return(Ok(new { Greet = greetingService.greet("Aniket") })); }
/// <summary> /// Set options for the region /// </summary> private void SetRegionOptions() { company = Factory.CreateBiggestCompany(); capital = Factory.CreateCapital(); currency = Factory.CreateCurrency(); flagColors = Factory.CreateFlagColors(); foundationYear = Factory.CreateFoundationYear(); greetings = Factory.CreateGreetings(); language = Factory.CreateLanguage(); mostPopularReligion = Factory.CreateReligion(); timeZone = Factory.CreateTimeZone(); typeOfCountry = Factory.CreateTypeOfCountry(); }
public void RunInvokation() { var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent($"\"{HelloWorld}\"", Encoding.UTF8, "application/json") }; _client = new Mock <IHttpClient>(); _client.Setup(s => s.SendAsync(It.IsAny <HttpRequestMessage>())).ReturnsAsync(httpResponseMessage); _invokation = new Mock <IInvocation>(); _invokation.SetupGet(i => i.Method).Returns(typeof(IGreetings).GetMethod("Hello")); _invokation.SetupGet(i => i.Arguments).Returns(new object[] { 1555 }); _invokation.SetupGet(i => i.Proxy).Returns(typeof(IGreetings)); _invokation.SetupProperty(i => i.ReturnValue); var client = new HttpApiClient(_client.Object); apiClient = client.GetHttpApi <IGreetings>("http://localhost"); ((IInterceptor)client).Intercept(_invokation.Object); }
public SeasonHttpFunction(IGreetings greetings, IConfiguration configuration) { _configuration = configuration; _greetings = greetings; }
public void CallbackExample1() { //Start service and use net.tcp binding ServiceHost eventServiceHost = new ServiceHost(typeof(GreetingsService)); NetTcpBinding tcpBindingpublish = new NetTcpBinding(); tcpBindingpublish.Security.Mode = SecurityMode.None; eventServiceHost.AddServiceEndpoint(typeof(IGreetings), tcpBindingpublish, "net.tcp://localhost:8000/GreetingsService"); var cd = eventServiceHost.Description.Endpoints [0].Contract; Assert.AreEqual(2, cd.Operations.Count, "Operations.Count"); var send = cd.Operations.FirstOrDefault(od => od.Name == "SendMessage"); var show = cd.Operations.FirstOrDefault(od => od.Name == "ShowMessage"); Assert.IsNotNull(send, "OD:SendMessage"); Assert.IsNotNull(show, "OD:ShowMessage"); foreach (var md in send.Messages) { if (md.Direction == MessageDirection.Input) { Assert.AreEqual("http://tempuri.org/IGreetings/SendMessage", md.Action, "MD:SendMessage"); } else { Assert.AreEqual("http://tempuri.org/IGreetings/SendMessageResponse", md.Action, "MD:SendMessage"); } } foreach (var md in show.Messages) { if (md.Direction == MessageDirection.Output) { Assert.AreEqual("http://tempuri.org/IGreetings/ShowMessage", md.Action, "MD:ShowMessage"); } else { Assert.AreEqual("http://tempuri.org/IGreetings/ShowMessageResponse", md.Action, "MD:ShowMessage"); } } eventServiceHost.Open(); var chd = (ChannelDispatcher)eventServiceHost.ChannelDispatchers [0]; Assert.IsNotNull(chd, "ChannelDispatcher"); Assert.AreEqual(1, chd.Endpoints.Count, "ChannelDispatcher.Endpoints.Count"); var ed = chd.Endpoints [0]; var cr = ed.DispatchRuntime.CallbackClientRuntime; Assert.IsNotNull(cr, "CR"); Assert.AreEqual(1, cr.Operations.Count, "CR.Operations.Count"); Assert.AreEqual("http://tempuri.org/IGreetings/ShowMessage", cr.Operations [0].Action, "ClientOperation.Action"); //Create client proxy NetTcpBinding clientBinding = new NetTcpBinding(); clientBinding.Security.Mode = SecurityMode.None; EndpointAddress ep = new EndpointAddress("net.tcp://localhost:8000/GreetingsService"); ClientCallback cb = new ClientCallback(); IGreetings proxy = DuplexChannelFactory <IGreetings> .CreateChannel(new InstanceContext (cb), clientBinding, ep); //Call service proxy.SendMessage(); //Wait for callback - sort of hack, but better than using wait handle to possibly block tests. Thread.Sleep(2000); //Cleanup eventServiceHost.Close(); Assert.IsTrue(CallbackSent, "#1"); Assert.IsTrue(CallbackReceived, "#2"); }
public GreetingsController(IGreetings greetings) { igreetings = greetings; }
public void Construct(IGreetings greeting) { this.greeting = greeting; }
public HomeController(IRestaurantRepository restaurantRepository, IGreetings greetings) { _restaurantRepository = restaurantRepository; _greetings = greetings; }
public GreetController(IGreetings greetings) { this.greet = greetings; }