Note that there are some explanatory texts on larger screens.

plurals
  1. POStructuremap: Scan Folder, instantiate Class by name (For<ITest>.Use(string))
    primarykey
    data
    text
    <p>I'm trying to use Structuremap, which gives me a hard time since the documentation on the structure-map-site is pretty old (most the time I work with the provided code, I get an obsolete-msg in VS...)</p> <p>Anyway, I'm trying to provide something like this:</p> <pre><code>private static ITest GetInstance() { return (new Container(x =&gt; x.For&lt;ITest&gt;().Use&lt;Test2&gt;())).GetInstance&lt;ITest&gt;(); } </code></pre> <p>This piece of code works fine, BUT now I'm trying to achieve the same thing without the Class "Test2" in this project. My goal is: I want to have a folder with all kind of .dlls, which provides ITest-Methods (like Test1, Test2, Test3, aso). Structuremap should register those dlls (x.Scan(s => s.AddAllTypesOf)) and with a simple string I want to tell my application to use "Test2".</p> <p>Here is my idea in code-form (not working):</p> <pre><code>public static class TestHandler { static TestHandler() { Tests = new Container(); Tests.Configure(x =&gt; x.Scan(scanner =&gt; { scanner.AssembliesFromPath(@"TestCases"); scanner.AddAllTypesOf&lt;ITest&gt;(); scanner.LookForRegistries(); })); } public static Container Tests { get; set; } public static ITest GetHandler(string handlerName) { return Tests.Configure(x =&gt; x.For&lt;ITest&gt;().Use(handlerName))) .GetInstance&lt;ITest&gt;(handlerName); } } </code></pre> <p>So how can I create an object, which I can pass then .Use? And what variable would I have to pass anyway?</p> <p>If I have to guess, I would say one of those:</p> <ul> <li>Full qualified Assembly Name</li> <li>Just the name of the class (which would be in this case Test2)</li> <li>AssemblyName.ClassName</li> </ul> <p>I tried the WhatDoIhave()-Method, which gives me:</p> <blockquote> <p>ITest (smTests.ITest) TestExample1.FirstName, TestExample1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Configured Instance of TestExample1.FirstName, TestExample1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Scoped as: Transient</p> </blockquote> <p>From that I'm quite positive that I have to use TestExample1.FirstName. But how can I create an Instance in the first place?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload