Use of Autopoco

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.