Note that there are some explanatory texts on larger screens.

plurals
  1. POServicestack - Inject class that have constructor
    primarykey
    data
    text
    <p>I Have class that have some property injection like this:</p> <pre><code>public class MyRepository { public IBaseRepository BaseRepository { get; set; } //Injected By IoC public IUid Uid { get; set; } // Injected By IoC private static AnotherClass _anotherClass; public MyRepository() { _anotherClass = BaseRepository.Db.SingleOrDefault&lt;AnotherClass&gt;(); //another logic in here.... } public string MethodUsingUid() { return Uid.SomeMethodHere(_anotherClass); } } </code></pre> <p>And used by Services like this:</p> <pre><code>public class TheServices : Service { public MyRepository Repo { get; set; } public object Post(some_Dto dto) { return Repo.MethodUsingUid(); } } </code></pre> <p>And my Apphost.configuration looks like this: </p> <pre><code> container.Register&lt;IDbConnectionFactory&gt;(conn); container.Register&lt;IBaseRepository&gt;(c =&gt; new BaseRepository(){ DbFactory = c.Resolve&lt;IDbConnectionFactory&gt;()}).ReusedWithin(ReuseScope.Request); container.Register( c =&gt; new MyRepository() { BaseRepository = c.TryResolve&lt;IBaseRepository&gt;(), Uid = c.TryResolve&lt;Uid&gt;() }); container.RegisterAutoWired&lt;Uid&gt;().ReusedWithin(ReuseScope.Request); </code></pre> <p>I know it will not injected because it will created before funq have chances to inject. and according to this answer: <a href="https://stackoverflow.com/questions/14486462/servicestack-dependency-seems-to-not-be-injected">ServiceStack - Dependency seem's to not be Injected?</a></p> <p>I need to move the constructor into Apphost.config() My question is, how I move this class constructor out into apphost.config()? and how to manage that if I have many class like that?</p>
    singulars
    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.
 

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