Last active
December 19, 2015 05:49
-
-
Save aruss/5907357 to your computer and use it in GitHub Desktop.
Kooboo UUIDGenerator with IoC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IUUIDGenerator | |
{ | |
string Generate(ContentBase content); | |
} | |
public class GuidUIIDGenerator : IUUIDGenerator | |
{ | |
[DllImport("rpcrt4.dll", SetLastError = true)] | |
private static extern int UuidCreateSequential(out Guid guid); | |
const int RPC_S_OK = 0; | |
public static Guid NewSequentialGuid() | |
{ | |
Guid guid; | |
int result = UuidCreateSequential(out guid); | |
if (result == RPC_S_OK) | |
return guid; | |
else | |
return Guid.NewGuid(); | |
} | |
public string Generate(ContentBase content) | |
{ | |
return GuidUIIDGenerator.NewSequentialGuid().ToString(); | |
} | |
} | |
public class UUIDGenerator | |
{ | |
static UUIDGenerator() | |
{ | |
DefaultGenerator = EngineContext.Current.ContainerManager.Resolve<IUUIDGenerator>(); | |
} | |
public static IUUIDGenerator DefaultGenerator { get; set; } | |
public virtual string Generate(ContentBase content) | |
{ | |
return UUIDGenerator.DefaultGenerator.Generate(content); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, it is better. Actually you can inherit from UUIDGenerator