Featured post
ComponentNotFound exception Castle.Windsor -
i trying started castle.windsor , following comment made on samples available newbies (http://stw.castleproject.org/windsor.silvertlight_sample_app_customer_contact_manager.ashx?discuss=1), thought i'd take bull horns , update example provided here http://dotnetslackers.com/articles/designpatterns/inversionofcontrolanddependencyinjectionwithcastlewindsorcontainerpart1.aspx.
this simple , straightforward console application making use of castle windsor, albeit outdated version. main method in program.cs follows:
public static void main() { iwindsorcontainer container = new windsorcontainer(); container.install(fromassembly.this()); var retriever = container.resolve<ihtmltitleretriever>(); console.writeline(retriever.gettitle(new uri(configurationmanager.appsettings["fileuri"]))); console.read(); container.dispose(); }
and service , components, in same file i.e. program.cs thus:
public interface ihtmltitleretriever { string gettitle(uri file); } public interface ifiledownloader { string download(uri file); } public interface ititlescraper { string scrape(string filecontents); } public class htmltitleretriever: ihtmltitleretriever { private readonly ifiledownloader _downloader; private readonly ititlescraper _scraper; public htmltitleretriever(ifiledownloader dowloader, ititlescraper scraper) { _downloader = dowloader; _scraper = scraper; } public string gettitle(uri file) { string filecontents = _downloader.download(file); return _scraper.scrape(filecontents); } } public class httpfiledownloader : ifiledownloader { public string download(uri file) { return new webclient().downloadstring(file); } } public class stringparsingtitlescraper : ititlescraper { public string scrape(string filecontents) { string title = string.empty; int openingtagindex = filecontents.indexof("<title>"); int closingtagindex = filecontents.indexof("</title>"); if(openingtagindex != -1 && closingtagindex != -1) title = filecontents.substring(openingtagindex, closingtagindex - openingtagindex).substring(7); return title; } }
it pretty straight copy of simone busoli has example. code compiles fine following error when run application:
no component supporting service windsorsample.ihtmltitleretriever found
i understand means don't know i'm doing wrong components not getting loaded container. i'm using castle.windsor 2.5.2 , .net 4.0.
looking forward answers,
david
first of - awesome you're updating sample. mentioned, smaller sample, without silverlight overhead useful.
as question - exception means service requested, ihtmltitleretriever
not supported component registered, in other words - didn't seem have registered ihtmltitleretriever
in container @ all. how installer like? check if components registered can put breakpoint in line after call install
, see components registered, , if that's expecting. it's quite useful diagnosing issues 1 you're having. (see documentation here).
if you're still not sure reason is, make sure installer classes public, , post code here can try figure out what's reason.
- Get link
- X
- Other Apps
Comments
Post a Comment