Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I force Unity App Block to load new Object instances in WCF?
    primarykey
    data
    text
    <p>I am using Unity Application Block to load my dependancies, a problem I am having is when all my dependancies are loaded it is behaving abnormally.</p> <p>I have a service that takes a business interface using constructor injection, and that business interface takes a repository interface as constructor injection. The problem I have is when I load user details from the database the field values are always the same (even after I manually change them in the DB). Therefore I think it is because it is using the same instance EntityFramework context instance for each time the service is opened.</p> <p>The only way I can get Entity Framework to load the correct details is to recycle IIS.</p> <p>Is there a way I can force Unity to create new object instances for its dependancies and force them to be dispose when the WCF request has completed? I have tried using the transient lifetime manager but this is not curing the problem. </p> <p><strong>Code:</strong></p> <pre><code>public class UserService : IUserService { private IUserAdmin _UserBusiness { get; set; } public UserService() { } [InjectionConstructor] public UserService(IUserAdmin userBusiness) : this() { this._UserBusiness = userBusiness; } } public class UserAdmin : BusinessBase, IUserAdmin { private IRepository&lt;DBUserAccount&gt; _UserRepository { get; set; } [InjectionConstructor] public UserAdmin(IRepository&lt;DBUserAccount&gt; userRepository) { this._UserRepository = userRepository; } } public class GenericRepository&lt;T&gt; : IDisposable, IRepository&lt;T&gt; where T : class, new() { private Entities _Context; private ObjectSet&lt;T&gt; _ObjectSet; public GenericRepository() { this._Context = new Entities(); this._ObjectSet = this._Context.CreateObjectSet&lt;T&gt;(); } } </code></pre> <p>Unity Config:</p> <pre><code>&lt;register type="Services.Contracts.IUserService, Server.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be" mapTo="Services.Implementations.UserService, Server.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be"&gt; &lt;lifetime type="transient"/&gt; &lt;/register&gt; &lt;register type="Server.Business.Users.IUserAdmin, Server.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be" mapTo="Server.Business.Users.UserAdmin, Server.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be"&gt; &lt;lifetime type="transient"/&gt; &lt;/register&gt; &lt;register type="Server.DataLogic.IRepository`1[[Server.DataModels.DBUserAccount, Server.DataModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be]], Server.DataLogic, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be" mapTo="Server.DataLogic.GenericRepository`1[[Server.DataModels.DBUserAccount, Server.DataModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be]], Server.DataLogic, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 683f160d975782be"&gt; &lt;lifetime type="transient"/&gt; &lt;/register&gt; </code></pre>
    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.
 

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