Codoxide.Common Library Version 0.0.1 (Concept Phase): Database Wrapper, Basic Design Patterns, Configuration Handlers
 

by Sameera on October 20, 2008 11:18

Today I'm so excited to announce the first release of the Codoxide.Common Library. High Five! I haven't been over ambitious about the version numbering as I want you to treat this library to still be in concept stage.   Codoxide.Common Library Released

Unfortunately, this release had taken longer than expected cos of my newly cramped up schedule. Worst part of that is I'm posting this code without proper documentation (yep, excuses!). Nevertheless, there's plenty of code in here to prove useful to many. So here goes!

Features/Components

Patterns

  • SharedInstance<T>
  • Singleton<T>
  • Factory e.g. Factory.Build<T>()

Configuration

  • ConfigurationManager<T>
  • ConfigurationSectionBase

Data

  • Database<CONNECTION_TYPE, COMMAND_TYPE, ADAPTER_TYPE>
  • Map<T>

 

SharedInstance<T>

SharedInstance is actually the most basic type of generic Singleton implementation that's been around in the C# community. This implementation was both simple and efficient. But, it violated the definition of a Singleton by depending on the presence of a public constructor and thereby allowing additional instances to be created. Therefore, I have refrained from calling this a Singleton resorted to the term SharedInstance.

E.g:

[code:c#]
SharedInstance<User>.Instance.Login("admin", "password");

User employee1 = new User();
employee1.Username = "emp001";
employee1.Password = "pass001";
employee1.Save();
[/code]

Singleton<T>

More advanced implementation of the generic Singleton implementation. Uses reflection, custom attributes and "lazy initialization" to provide a powerful way to create and initialize your singletons.

E.g:

[code:c#]
public class UserPreferences : IXmlSerializable, ISupportLazyInitialization
{
    ..

    public virtual void Initialize()
    {
        try
        {
            string location = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Codoxide\\preference.xml";
            if (File.Exists(location))
                using (XmlReader reader = XmlReader.Create(location))
                {
                    reader.ReadToFollowing("Preferences");
                    this.ReadXml(reader);
                    reader.ReadEndElement();
                }
        }
        catch (Exception ex)
        {
            throw new InvalidConfigurationException("Exception occurred while loading the preferences from disk", ex);
        }
    }
    ..
}

...

Console.WriteLine(Singleton<UserPreferences>.Instance.BackgroundColor);
[/code]

Factory.Build<T>

This one's another powerful and unique implementation. Coolest feature of this class is that you can do something like the following:

[code:c#]
using (IDatabase db = Factory.Build<IDatabase>())
{
    ..
}
[/code]

This allows developers of class libraries to write their code using interfaces or abstract classes, leaving the library users to specify the concrete classes via configuration files.

Grab the Code

There's of course, plenty more to be documented regarding the library. And you can expect the project space to be updated in coming (err..) weeks Wink.

Until then, you can:

Check out the code (using SVN): https://codoxidelib.svn.sourceforge.net/svnroot/codoxidelib/trunk

Browse the project space: http://codoxidelib.sourceforge.net/

Add comment


(Will show your Gravatar icon)  

biuquote
  • Comment
  • Preview
Loading



About Me

Sameera Perera

Sameera Perera

Log in

RecentComments

Comment RSS

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

Archive

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

All forms of source code published on Codoxide.com are distributed under the Apache License, Version 2.0 unless otherwise stated.
The rest of the content are published under a Creative Commons Attribution 3.0 License.
Creative Commons License

CodoxideTM

Copyright © 2009  codoxide.com. All rights reserved. Designed by Sameera Perera