Official Development Guide Https://autopoco.codeplex.com/documentation
Initial use:
Simpleuser is the class you want to create in bulk
1) Create a management plant
Igenerationsessionfactory factory = autopococontainer.configure (x =
{
X.conventions (c =
{
C.usedefaultconventions ();
});
X.addfromassemblycontainingtype<simpleuser> ();
});
2) Create a session from the factory
Igenerationsession session = Factory. CreateSession ();
3) Create a collection with a session, and 100 in the list creates a collection of 100 elements that are not assigned to the elements in the collection when created.
Simpleuser user = session. Single<simpleuser> (). Get ();
List<simpleuser> users = Session. List<simpleuser> (100). Get ();
On a preliminary basis to assign values
Session. List<simpleuser> (100)
. First (50)
. Impose (x = x.firstname, "Rob")
. Impose (x = x.lastname, "Ashton")
. Next (50)
. Impose (x = x.firstname, "Luke")
. Impose (x = x.lastname, "Smith")
. All (). Random (25)
. Impose (x = x.role,roleone)
. Next (25)
. Impose (x = x.role,roletwo)
. Next (50)
. Impose (x = x.role, Rolethree)
. All ()
. Invoke (x = X.setpassword ("Password1"))
. Get ();
Test findings:
1. The next method must be used after first or random, and first can only be used once without calling the all method, first, Random, next must call the all method after use;
2, can only assign a value to one attribute at a time;
Creating from the data source
MFactory = autopococontainer.configure (x =
{
X.conventions (c =
{
C.usedefaultconventions ();
});
X.addfromassemblycontainingtype<simpleuser> ();
X.include<simpleuser> ()
. Setup (c = c.emailaddress). Use<emailaddresssource> ()
. Setup (c = c.firstname). Use<firstnamesource> ()
. Setup (c = c.lastname). Use<lastnamesource> ()
. Invoke (c = C.setpassword (use.source<string, passwordsource> ()));
X.include<sometype> ()
. Setup (c = c.somestring). Use<randomstringsource> (5,10);
});
A generic in use is a class that is passed to the collection element instance data source. The class must inherit the abstract generic class datasourcebase<t> generic T to represent the data type of the corresponding property. There is only one abstract method in the abstract class next, which is to return the data to the property and implement the property assignment. So as to achieve data binding;
Implementing data source bindings in conventions
For example
A convention to set any String EmailAddress properties to use the Emailaddresssource
public class Emailaddresspropertyconvention:itypepropertyconvention
{
public void Apply (Itypepropertyconventioncontext context)
{
Context. Setsource<emailaddresssource> ();
}
public void specifyrequirements (itypememberconventionrequirements requirements)
{
Requirements. Name (x = String.Compare (x, "EmailAddress", true) = = 0);
Requirements. Type (x = x = = typeof (String));
}
}
A convention to set any String emailaddress fields to use the Emailaddresssource
public class Emailaddressfieldconvention:itypefieldconvention
{
public void Apply (Itypefieldconventioncontext context)
{
Context. Setsource<emailaddresssource> ();
}
public void specifyrequirements (itypememberconventionrequirements requirements)
{
Requirements. Name (x = String.Compare (x, "EmailAddress", true) = = 0);
Requirements. Type (x = x = = typeof (String));
}
}
X.conventions (c = c.register (typeof(idpropertyconvention)));
X.addfromassemblycontainingtype<simpleuser> ();
In the context there is a SetValue method, should be to the binding data source value, test use when there is no effect, pass multiple value theory is the use of the array. The problem is not resolved.
Use of Autopoco