×

Notice

The forum is in read only mode.
×
Getting new Releases

To get notified on new releases you may follow us on twitter @expandframework or subscribe in our main RSS feed.

Topic-icon How about Making SequenceGenerator as a ServiceClass Like following

  • K1
  • K1's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
1 year 10 months ago #10876 by K1
How about Making SequenceGenerator as a Service Class Like following :
private class SequenceGenerator : IDisposable {
	/* All instance code here */
}
public static class SequenceService {
	static SequenceGenerator _sequenceGenerator;

	public static void GenerateSequence(ISessionProvider SessionProvider,string SequenceId, string SequencePrefix){
		/*Code here*/
	}
	
	public static void ReleaseSequence(XPObjectSpace object,string SequenceId, string SequencePrefix){
		/*Code here*/
	}
	public static void ReleaseSequence(IObjectSpace objectSpace,string SequenceId, string SequencePrefix){
		/*Code here*/
	}	
}



Then We can use it with following API
public class Invoice : BaseObject {
	
	public string Id { ... }
	public string Id2 { ... }

	protected override void OnSaving() {
		base.OnSaving();
		Id = SequenceGenerator.GenerateSequence(this, "Invoice", "AA" );
		Id2 = SequenceGenerator.GenerateSequence(this, "Invoice", "BB" );
	}
	
  protected override void OnDeleted() {
		base.OnDeleted();
        SequenceGenerator.ReleaseSequence(this "Invoice", "AA" );
        SequenceGenerator.ReleaseSequence(this "Invoice", "AA" );
	}	
} 
The following user(s) said Thank You: Tolis
More
1 year 10 months ago #10877 by Tolis
Hi

thnks for the suggestion however it is not clear what the benefits of this refactor from what I see the current calls are similar github.com/expand/eXpand/blob/bdb4d9e1b1...neratorObject.cs#L47 can you elab further?

To get notified on new releases follow us on twitter @expandframework or subscribe RSS feed. I am also available @tolisss . Also see How to debug eXpand
  • K1
  • K1's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
1 year 10 months ago #10881 by K1
Thanks for your reply,

There are many benefits some of them are :
Benefit 1:
No need to have interface like "ISupportSequenceObject"
As adding/using SequenceService can be done with only two lines at any time.

Benefit 2:
No need to have properties like :
public long Sequence { get; set; }

then we hide it with
[InvisibleInAllViews]
public long Sequence { get; set; }
especially if the real Sequence property will be string with prefix for example "AA0001"

Benefit 3:
Current Implementation doesn't allow for two properties in same object like my example Id, Id2
Real life example : Order has OrderId and based on order type Id2 will be filled with different Prefixes.

Benefit 4:
"SequenceGenerator" class can based in interface somthing like "ISequenceGenerator" then used with some DI.

Benefit 5:
Using Object Type FullName as Sequence Id is very dangerous (Or risky, error prone)
As ant any time in project lifetime or in future updates a refactoring is done to Object "Order" and namespaces is changed Issues will happens.
Especially if developer doesn't/forgot the impact of namespace change

More worst if application deployed to production and a few new sequence numbers are generated.

And even so to replicate the namespace change require updating the sequence table in Database directly.
But using "string SequenceId" explicitly will not introduce this issue.

Benefit 6:
Having a scenario when multiple classes need to share same Sequence will not work with current implementation.
But allow to explicitly provide SequenceId will help.
  • K1
  • K1's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
1 year 10 months ago #10882 by K1
Also It will be nice if We can introduce a member Attribute with a constructor like
SequenceAttribute(string SequenceID, string Template,bool ReuseDeleted)

Then It can be used like :
public class Invoice : BaseObject {
	[Sequence("Invoice.Id",  "AA-{0}", true)]
	public string Id { ... }

	[Sequence("Invoice.Id2",  "BB-{0}-X", true)]
	public string Id2 { ... }	
} 

Although I didn't look yet at technical implementation of it. But Still "ISequenceGenerator" approach is the most flexible as OnSaving we can use different SequenceID and Templates based on any conditions.

But for most simple scenarios one Attribute can do it all.
Thanks
The following user(s) said Thank You: Tolis
More
1 year 10 months ago #10883 by Tolis
thnks for the feedback it is now clear what you suggest.

I will add it to my todo list but if you interested to try an implementation let me know so we do not duplicate efforts

To get notified on new releases follow us on twitter @expandframework or subscribe RSS feed. I am also available @tolisss . Also see How to debug eXpand
More
1 year 9 months ago #10911 by Tolis
your suggestions are implemented in 17.1.3.8, please explorer ther related easytest

github.com/expand/eXpand/blob/6b3709abf3...equenceGenerator.ets

To get notified on new releases follow us on twitter @expandframework or subscribe RSS feed. I am also available @tolisss . Also see How to debug eXpand
Moderators: expand
Time to create page: 0.304 seconds