0
I’m doing a gateway to a client project consuming Microservices. In this gateway, the way the client will consume the application is through an interface. The implementation of this interface will be created dynamically (At compile time). So I need to know how to inject the dynamically generated class dependency. Example:
[MicroServiceHost("MsProduct")]
public interface IProductService
{
[MicroService("GetAllProducts")]
IRestResponse GetAllProducts(List<KeyValuePair<object, object>> parameters = null);
[MicroService("AddProduct")]
IRestResponse AddProduct(List<KeyValuePair<object, object>> parameters = null);
}
public class MsProductController : Controller
{
IProductService _productService;
public MsProductController(IProductService productService)
{
_productService = productService;
}
public ActionResult GetAll()
{
var request = _productService.GetAllProducts();
var r = request.Content;
return View();
}
}
Please, either Ask this Question on SO-EN or Translate this Question to English. tyvm
– mutlei
Your question is very wide, it would be nice to put the code of this class... I recommend reading: https://www.devmedia.com.br/introducao-a-injecao-de-dependencia-no-asp-net-mvc/27099
– wDrik
I don’t understand, do you want to implement dependency injection in a project of yours? Is that it? I also think the question has nothing to do with "Microservices"
– Guilherme Nascimento
@Guilhermenascimento I think he wants to "inject the dependency" into an instance (object) created via Reflection. Confer, Guilhermeramos?
– Jéf Bueno
Whereas is this hypothesis, will you load the object from the same dll? Or will you load the dll first?
– Eric Wu
@LINQ was what I imagined, only that the Microservices tag simply made no sense and not even if it had to do with the "early" part: it creates a "dynamic class".
– Guilherme Nascimento
Sorry for the way of the question. Adjusting. I am making a gateway for a customer to consume Microservices. In this gateway, the way the client will consume the application is through an interface. The implementation of this interface will be created dynamically (At compile time). So I need to know how to inject the dynamically generated class dependency.
– Guilherme Ramos
The MEF can’t help you in this case?
– Gabriel Heming
Thanks @Gabrielheming , worked out. I will write how I solved and will assign you the credits !
– Guilherme Ramos
@Guilhermeramos Excellent! I will be waiting for the implementation.
– Gabriel Heming