× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

What is the syntax for creating an instance of UserManager actually doing?

Steven Doggart
Jul 01, 2015
<p>The following line of code:</p> <pre><code>Dim myUserManager = New UserManager(Of ApplicationUser)(New UserStore(Of ApplicationUser)(New ApplicationDbContext)) </code></pre> <p>Is equivalent to this:</p> <pre><code>Dim myApplicationDbContext As New ApplicationDbContext Dim myUserStore As New UserStore(Of ApplicationUser)(myApplicationDbContext) Dim myUserManager = New UserManager(Of ApplicationUser)(myUserStore) </code></pre> <ol> <li>The first step is to create a new <code>ApplicationDbContext</code> object, which takes no arguments to its <a href="https://msdn.microsoft.com/en-us/library/2z08e49e(v=vs.90).aspx" rel="nofollow">constructor</a>. </li> <li>The second step is to create a new <code>UserStore(Of ApplicationUser)</code> object, which takes the already created <code>ApplicationDbContext</code> object as an argument to its constructor. </li> <li>The third step is to create a new <code>UserManager(Of ApplicationUser)</code> object, which takes the already created <code>UserStore(Of ApplicationUser)</code> object as an argument to its constructor.</li> </ol> <p>The <code>(Of ...)</code> part of the type name is a generic parameter. .NET supports <a href="https://msdn.microsoft.com/en-us/library/vstudio/w256ka79(v=vs.100).aspx" rel="nofollow">generic types</a>. The part after <code>Of</code> is a type parameter to the generic class. So, just as <code>Dim x As New List(Of String)</code> creates a list of strings, <code>UserStore(Of ApplicationUser)</code> creates a user-store for storing application-users.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/28817645/What%20is%20the%20syntax%20for%20creating%20an%20instance%20of%20UserManager%20actually%20doing?/28818276">Stack Overflow</a>.</p>
comments powered by Disqus