Skip to content

Commit

Permalink
Merge pull request #55 from mhelvacikoylu/v2
Browse files Browse the repository at this point in the history
2.7.14
  • Loading branch information
mhelvacikoylu committed Feb 28, 2020
2 parents 3f89e97 + a10dd90 commit 9a381b0
Show file tree
Hide file tree
Showing 38 changed files with 587 additions and 228 deletions.
99 changes: 49 additions & 50 deletions src/Samples/Playground/Program.cs
Original file line number Diff line number Diff line change
@@ -1,90 +1,89 @@
using System;
using System.Reflection;
using System.Linq;
using System.Threading.Tasks;
using Twino.Ioc;
using Twino.MQ.Data;
using Twino.Mvc;
using Twino.Mvc.Controllers;
using Twino.Mvc.Controllers.Parameters;
using Twino.Mvc.Filters.Route;
using Twino.Protocols.TMQ;
using Twino.Server;

namespace Playground
{

interface IService1
public class Login
{
void Test1();
public string User { get; set; }
public string Pass { get; set; }
}

interface IService2
public class User
{
void Test2();
public string Name { get; set; }
public string Lastname { get; set; }
}

class Service1 : IService1
[Route("x")]
public class BController : TwinoController
{

public void Test1()
[HttpGet("c/{?x}")]
public async Task<IActionResult> C(string x)
{
Console.WriteLine("echo 1");
return await StringAsync("Xhello: " + x);
}
}

class Service2 : IService2
{
public void Test2()
{ }
}
[HttpGet("")]
public async Task<IActionResult> B()
{
return await StringAsync("Xhello");
}

interface IService3 { }
class Service3 : IService3
{
public Service3(IService1 service1)
[HttpGet("d")]
public async Task<IActionResult> D()
{
service1.Test1();
return await StringAsync("Xhello D");
}
}

class Service1Proxy : IServiceProxy

[Route("")]
public class AController : TwinoController
{
private IService2 _service2;
public Service1Proxy(IService2 service2)
[HttpGet("c/{?x}")]
public async Task<IActionResult> C(string x)
{
_service2 = service2;
return await StringAsync("hello: " + x);
}

public object Proxy(object decorated)
[HttpGet("")]
public async Task<IActionResult> B()
{
return DenemeDispatchProxy<IService1>.Create((IService1)decorated, _service2);
return await StringAsync("hello");
}
}


class DenemeDispatchProxy<T> : DispatchProxy
{
private T _decorated;
private IService2 _service2;
public static T Create(T decorated, IService2 service2)
[HttpGet("d")]
public async Task<IActionResult> D()
{
object proxy = Create<T, DenemeDispatchProxy<T>>();
DenemeDispatchProxy<T> instance = (DenemeDispatchProxy<T>)proxy;
instance._decorated = decorated;
instance._service2 = service2;
return (T)proxy;
return await StringAsync("hello D");
}

protected override object Invoke(MethodInfo targetMethod, object[] args)
[HttpGet("e/{x}")]
public async Task<IActionResult> E(string x)
{
Console.WriteLine("PROXY");
return targetMethod.Invoke(_decorated, args);
return await StringAsync("hello E: " + x);
}
}

class Program
{
static async Task Main(string[] args)
static void Main(string[] args)
{
var container = new ServiceContainer();
container.AddSingleton<IService1, Service1, Service1Proxy>();
container.AddSingleton<IService2, Service2>();
container.AddSingleton<IService3, Service3>();
var instance3 = await container.Get<IService3>(container.CreateScope());
Console.ReadLine();
TwinoMvc mvc = new TwinoMvc();
mvc.Init();
TwinoServer server = new TwinoServer();
server.UseMvc(mvc);
server.Start(26222);
server.BlockWhileRunning();
}
}
}
2 changes: 1 addition & 1 deletion src/Samples/Sample.Mvc/Controller/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public IActionResult IT()
}

[HttpPost("post")]
public async Task<IActionResult> Post([FromBody] LoginModel model)
public async Task<IActionResult> Post([FromForm] LoginModel model)
{
return await JsonAsync(new
{
Expand Down
4 changes: 2 additions & 2 deletions src/Samples/Sample.Mvc/Controller/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

namespace Sample.Mvc.Controller
{
[Route("")]
[Route("a")]
public class HomeController : TwinoController
{
[HttpGet("")]
[HttpGet("b")]
public async Task<IActionResult> Get()
{
return await StringAsync("Welcome!");
Expand Down
146 changes: 146 additions & 0 deletions src/Tests/Test.Mvc/Controllers/TestControllers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System.Threading.Tasks;
using Twino.Mvc;
using Twino.Mvc.Controllers;
using Twino.Mvc.Filters.Route;

namespace Test.Mvc.Controllers
{
[Route("")]
[Route("test")]
[Route("[controller]")]
public class Test1Controller : TwinoController
{
[HttpGet("")]
public async Task<IActionResult> IndexGet()
{
return await StringAsync("get/");
}

[HttpPost("")]
public async Task<IActionResult> IndexPost()
{
return await StringAsync("post/");
}

[HttpGet("a")]
public async Task<IActionResult> GetA()
{
return await StringAsync("geta/");
}

[HttpPost("a")]
public async Task<IActionResult> PostA()
{
return await StringAsync("posta/");
}

[HttpGet("b/{?x}")]
public async Task<IActionResult> GetB(string x)
{
return await StringAsync($"getb/{x}");
}

[HttpPost("b/{?x}")]
public async Task<IActionResult> PostB(string x)
{
return await StringAsync($"postb/{x}");
}

[HttpGet("c/{x}")]
public async Task<IActionResult> GetC(string x)
{
return await StringAsync($"getc/{x}");
}

[HttpPost("c/{x}")]
public async Task<IActionResult> PostC(string x)
{
return await StringAsync($"postc/{x}");
}

[HttpGet("d/{x}/{?y}")]
public async Task<IActionResult> GetD(string x, string y)
{
return await StringAsync($"getd/{x}/{y}");
}

[HttpPost("d/{x}/{?y}")]
public async Task<IActionResult> PostD(string x, string y)
{
return await StringAsync($"postd/{x}/{y}");
}

[HttpGet("e/{x}/{y}")]
public async Task<IActionResult> GetE(string x, string y)
{
return await StringAsync($"gete/{x}/{y}");
}

[HttpPost("e/{x}/{y}")]
public async Task<IActionResult> PostE(string x, string y)
{
return await StringAsync($"poste/{x}/{y}");
}


[HttpGet("[action]")]
public async Task<IActionResult> GetAA()
{
return await StringAsync("geta/");
}

[HttpPost("[action]")]
public async Task<IActionResult> PostAA()
{
return await StringAsync("posta/");
}

[HttpGet("[action]/{?x}")]
public async Task<IActionResult> GetBB(string x)
{
return await StringAsync($"getb/{x}");
}

[HttpPost("[action]/{?x}")]
public async Task<IActionResult> PostBB(string x)
{
return await StringAsync($"postb/{x}");
}

[HttpGet("[action]/{x}")]
public async Task<IActionResult> GetCC(string x)
{
return await StringAsync($"getc/{x}");
}

[HttpPost("[action]/{x}")]
public async Task<IActionResult> PostCC(string x)
{
return await StringAsync($"postc/{x}");
}

[HttpGet("[action]/{x}/{?y}")]
public async Task<IActionResult> GetDD(string x, string y)
{
return await StringAsync($"getd/{x}/{y}");
}

[HttpPost("[action]/{x}/{?y}")]
public async Task<IActionResult> PostDD(string x, string y)
{
return await StringAsync($"postd/{x}/{y}");
}

[HttpGet("[action]/{x}/{y}")]
public async Task<IActionResult> GetEE(string x, string y)
{
return await StringAsync($"gete/{x}/{y}");
}

[HttpPost("[action]/{x}/{y}")]
public async Task<IActionResult> PostEE(string x, string y)
{
return await StringAsync($"poste/{x}/{y}");
}
}
}
Loading

0 comments on commit 9a381b0

Please sign in to comment.