-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from mhelvacikoylu/v2
2.7.14
- Loading branch information
Showing
38 changed files
with
587 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.