jfu
jfu

Reputation: 1700

@Autowired equivalent in Spring.net

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?

Upvotes: 2

Views: 6404

Answers (2)

FatTiger
FatTiger

Reputation: 737

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";
    }
  }

Upvotes: 0

Marijn
Marijn

Reputation: 10557

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.

Upvotes: 1

Related Questions