DI in Class Library inside S#arpLite Project

18 views
Skip to first unread message

ni...@customapp.co.za

unread,
Nov 26, 2013, 2:33:56 PM11/26/13
to sharp...@googlegroups.com
I'm adding a class library to my S#arpLite Solution.

Now in this class library I want to do dependency injection.  How do I go ahead to get that in place?

Sth in the line of:

public class MyStuffHelper  {
  private readonly IRepository<MyStuff> _repository;

  public AddAThing(MyStuff thing) {
    _repository.SaveOrUpdate(thing)....

Make sense?

ps:  Great work on S#arpLite.  Using it exclusively on all projects.  :-)

Billy McCafferty

unread,
Dec 12, 2013, 11:26:48 PM12/12/13
to sharp...@googlegroups.com
Hi,

Are you wanting dependency injection into MyStuffHelper?  If so, you'll need to do two things:

1) setup the constructor of MyStuffHelper to accept the required dependencies; e.g.:

public MyStuffHelper(IRepository<MyStuff> repository) {
  ...
}


2) Register MyStuffHelper with the IoC that you're using (e.g., StructureMap or
CastleWindor).

Alternatively, you could pass dependencies into the constructor of a controller and then simply new MyStuffHelper(dependencies) to bypass having to hook it up to the IoC.

Sorry for the delayed response...hope this is helpful.

Billy McCafferty


--
You received this message because you are subscribed to the Google Groups "S#arp Lite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharp-lite+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages