[英]Dependency Injection containers - how do I get a specific instance of an object?
[英]How do I create a new object using dependency injection
目前,我有一個表單,用戶可以在其中創建一個新對象。 然后將其作為JSON傳遞到控制器。
我如何通過此JSON創建一個新對象以插入到我擁有的數據庫中,而無需這樣做
var x = new CustomObject {
ExampleField = JSONProperty,
ExampleField2 = JSONProperty2
};
repo.Create(x);
通常,您需要這樣的東西:
[HttPost]
public ActionResult CreateCustomer(string json)
{
var customer = JsonConvert.DeserializeObject<Customer>(json);
repo.Create(customer);
return View(customer);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.