How can i inject using annotation which is like a feature of Spring MVC
public class AccountController :Controller
{
[Injected] // Need like this annotation
private AccountService _accountService;
public AccountController(){
}
}
You may use Unity Container
Here is an example:
public class MyObject
{
private SomeOtherObject _dependentObject;
[Dependency]
public SomeOtherObject DependentObject
{
get { return _dependentObject; }
set { _dependentObject = value; }
}
}
And here is the resolution:
IUnityContainer uContainer = new UnityContainer();
MyObject myInstance = uContainer.Resolve<MyObject>();
// now access the property containing the dependency
SomeOtherObject depObj = myInstance.DependentObject;
In .Net core application no need to mention as injected annotation.you need to change your service as interface driven.
In solution startup page add below shown code before services.AddMvc();
services.AddTransient<IInterface, Service>();
and in controller make change as
public class AccountController :Controller
{
private IAccountService _accountService;
public AccountController(IAccountService accountService){
_accountService = accountService;
}
}