문제

Is there an [Autowired] attribute in Spring.net for C# that would work like the Java @Autowired annotation?

If not, is there any other way to specify that a field should be autowired?

도움이 되었습니까?

해결책

Autowiring is supported to some extent, but it is not nearly as advanced as other IOC containers for .Net.

You might also be interested in the CodeConfig project.

다른 팁

You can use https://github.com/kirov-opensource/NAutowired/blob/master/README.md

  [Route("api/[controller]")]
  [ApiController]
  public class FooController : ControllerBase {

    //Use Autowired injection.
    [Autowired]
    private readonly FooService fooService;

    [HttpGet]
    public ActionResult<string> Get() {
      return fooService == null ? "failure" : "success";
    }
  }

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top