Setting an entity's Authorizer

Posts   
 
    
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 18-Apr-2012 19:38:06   

Hi,

Can you give me a example or documents which shows how to set up AuthorizerToUse property of an entity object manually?

Rishi

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Apr-2012 06:02:31   

There are tree ways to set it, as explained in the documentation: - Manually - Overriding Entitiy's CreateAuthorizer method. - Using Dependency Injection.

Doing it manually is the easiest option. Say you have an authorizer GeneralAuthorizer, you just do:

someEntity.AuthorizerToUse = new GeneralAuthorizer;

You also can take a look to the Authorizer example in the Examples section on the website.

David Elizondo | LLBLGen Support Team
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 16-May-2012 21:16:40   

I would like to use manual way as you suggested.

someEntity.AuthorizerToUse = new GeneralAuthorizer;

How you will implement same set of code on Entity Collection ?

someEntityCollection.AuthorizerToUse is not available ?

daelmo wrote:

There are tree ways to set it, as explained in the documentation: - Manually - Overriding Entitiy's CreateAuthorizer method. - Using Dependency Injection.

Doing it manually is the easiest option. Say you have an authorizer GeneralAuthorizer, you just do:

someEntity.AuthorizerToUse = new GeneralAuthorizer;

You also can take a look to the Authorizer example in the Examples section on the website.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-May-2012 02:25:46   

This is per entity, as it's an entity property. You'll have to loop on the entities and set it one by one.

Also you may do the following:

By overriding the Entity method CreateAuthorizer. This is a protected virtual (Protected Overridable) method which by default returns null / Nothing. You can override this method in a partial class or user code region of the Entity class to create the Authorizer to use for the entity. The LLBLGen Pro runtime framework will take care of calling the method. One way to create an override for most entities is by using a template. Please see the LLBLGen Pro SDK documentation for details about how to write templates to generate additional code into entities and in separate files. Also please see Adding Adding your own code to the generated classes for details.

This will guarantee any created entity will have the oroperty set. (without using DI)

Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 17-May-2012 17:53:06   

I want to implement this while doing fetch. so when i am sending request by FetchEntityCollection, i dont have anything to loop as this is new collection and i want to implement authorizer while doing fetch. Your answer is valuable.

e.g.

Dim employeeEntityCollection As New Grb.Framework.Business.Lower.HelperClasses.EntityCollection(Of Grb.Framework.Business.Lower.EntityClasses.EmpGeneralEntity)

Dim filter As New SD.LLBLGen.Pro.ORMSupportClasses.RelationPredicateBucket() Dim predicateExpression As New SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression()

  predicateExpression.Add(Grb.Framework.Business.Lower.HelperClasses.EmpGeneralFields.Ssn = ssn)
  predicateExpression.Add(Grb.Framework.Business.Lower.HelperClasses.EmpGeneralFields.DomainId = domainId)

filter.PredicateExpression.Add(predicateExpression)

externalAdapter.FetchEntityCollection(employeeEntityCollection, filter, employeePreFetchPath)

Walaa wrote:

This is per entity, as it's an entity property. You'll have to loop on the entities and set it one by one.

Also you may do the following:

By overriding the Entity method CreateAuthorizer. This is a protected virtual (Protected Overridable) method which by default returns null / Nothing. You can override this method in a partial class or user code region of the Entity class to create the Authorizer to use for the entity. The LLBLGen Pro runtime framework will take care of calling the method. One way to create an override for most entities is by using a template. Please see the LLBLGen Pro SDK documentation for details about how to write templates to generate additional code into entities and in separate files. Also please see Adding Adding your own code to the generated classes for details.

This will guarantee any created entity will have the oroperty set. (without using DI)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-May-2012 01:17:14   

Don't you want the Authorizer set by default for any given instance of EmpGeneralEntity?