Friday, August 13, 2010

Intermittent Ea Fault On

Resources (Resources) - that is multilingual

Today short entry about the multilingual pages. I will be based on the files. Resx. The mechanism is built into the same platform, but the net will describe how and what solved in practice.


ResourceHelper

It is our object is to facilitate the collection of auxiliary files. Resx. It is also responsible for initialization of ResourceManager that is the main subject of the page. NET that allows you to manage resources. Class itself is not complicated. In addition to the init method has only one method that takes a string value from our resource files. Class it looks like this: public static
ResourceHelper class
{private static ResourceManager public static void Initialize (ResourceManager ResourceManager)
{
Check.Argument.IsNotNull (ResourceManager, "ResourceManager"); _resourceManager = ResourceManager;

} public static string GetErrorMessage (string key) {

string errorMessage = _resourceManager.GetString (key);

if (errorMessage == null) throw new ArgumentException
(_resourceManager.GetString (ResourceKey.Common.InvalidMessage));

return errorMessage;}


class itself is static. As you can see here there is also a class named ResourceKey. This class has all the information about the names of the variables in the files. Resx. I just do not have to always enter a string, just use an auxiliary class and in case of a change in only one place it will be necessary. Such a little easier:) In addition to the projections of newly added files. Resx is also a factory which generates all the appropriate ResourceManager which subsequently initiate our helper. It looks very simple: public class

ResourceManagerFactory: IResourceManagerFactory
{private ResourceManager
_resourceManager;

public ResourceManagerFactory ()
} {


CreateResourceManager public ResourceManager ()
 {if (null == _resourceManager) 
_resourceManager = new ResourceManager ("mForum.Resources.ErrorsAndExceptions.ErrorMessages" Assembly.GetExecutingAssembly ());

_resourceManager return;

}}

Sam ResourceManager constructor takes two arguments. 1 is the name of the class that was generated with the creation of a file. Resx. The second is a library which is located in the file.

contrast in views have accepted a little different approach when it comes to resources. Resources standardly that is internal are only available from the library but for me all the resources associated with the presentation layer will cause the public to what we can directly refer to the file. resx with our views.

In addition to these changes, of course, I added tests related to our ResourceHelperem.


Wednesday, August 11, 2010

Men's Full Elastic Waist Jeans

the Event Aggregator - What is this?

Today I would like to describe another pattern / mechanism that I will be using, and it aims to significantly simplify the code and eliminate unnecessary relationships between objects.


Event Aggregator
As mentioned earlier, this pattern / mechanism is intended to eliminate unnecessary relationships between objects. It provides a single source for multiple objects. In its simplest form it looks like the class so that the record which relate to a specific event to our event aggregator. These classes are called handles (handlers). However, when we send an event to the event aggregator, it selects all the fixtures which relate to an event, sends them to an event, and they no longer deal with the perception of these events and activities related shares. In my forum I will use a fairly simple solution because it does not need anything complicated. An event is just a simple object which must implement the interface IEvent. eg
Public class
UserCreatedEvent: IEvent {}
EventAggregator: IEventAggregator
{private readonly
SynchronizationContext _context; private readonly IListenerService _listenerService;
public EventAggregator (context SynchronizationContext , IListenerService listenerService)
{
 Check.Argument.IsNotNull (context, "context"); 
Check.Argument.IsNotNull (listenerService, "listenerService");

_context = context;
 _listenerService = listenerService; 
}

public void SendMessage<T>(T message) where T : IEvent
{
var listeners = _listenerService.GetListeners<T>();

SendAction(() => listeners.ForEach(x => SendMessageToListeners<T>(x, message)));
}

private void SendMessageToListeners<T>(IListenTo<T> x, T message) where T : IEvent
{
x.Handle(message);
}

private void SendAction(Action action)
{
_context.Send (state => action (), null);}

}

heart of the whole event aggregator function is SendMessageToListeners. This function is responsible for sending events to the recipients. All brackets (handlers) are recorded IoC container FOR IN. However ListenerService just takes all those that apply to this event. Then, using the event aggregator lambda been specifically send events to a specific fixture. Everything is of course wątkowo-safe (thread-safe). In the event that was to be an asynchronous call. It sounds terrible in Polish: P Event handler that is nothing but a class that implements intertejs IListenTo that looks like this: public interface

IListenTo \u0026lt;T> WHERE T: IEvent

{void Handle (T message);}


This is a normal class with a method that has a Handle on the event argument.

And now a practical example. Say to create a new user. With the creation of entails, giving him the basic rights, sending an email confirming his / her e-mail address. In the normal case, simply a method of forming wywołalibyśmy methods from other classes associated with these activities. That is: public void
CreateUser () {
 / / here share associated with the addition of 
's ...

_rolesService.AddRole ();
_emailService.SendEmail ();}


unnecessary connections are formed with various objects. In the event of any modification services related roles, or sending e-mails it is possible that it will be a need for change in many places in the code. In small systems, it is not a problem but if grown in a difficult work, upgrading the application. It solved the same task with our Event Handler. We CreatedUserEvent event.
 / / here we have a separate class is not related at all with the method CreateUser 
class VerificationEmailHandler: IListenTo \u0026lt;CreatedUserEvent> {};
class BasicRoleHandler: IListenTo \u0026lt;CreatedUserEvent> {};
//----------------------------- ---------------------------
CreateUser public void () {

/ / here share for adding user
...
CreatedUserEvent CreatedUserEvent event = new ();
_eventAggregator.SendMessage (testEvent);}
 

Immediately I can see the removed redundant links between the objects. Method CreatedUser have no idea about the other services (servicow) non-specifically with it. In addition, the code can easily expand with new fixtures, where appropriate, as simply register a new handle, and it will be executed. You do not need any code changes.

Apart from the Event Handler, of course, I added a test associated with it. Thus created a new test project associated with mForum.Core. That's all for today:)


Tuesday, August 10, 2010

Diagram Of A Theme Park

Infrastructure related closely with Asp.net MVC ...

Now the time has come for the basic infrastructure for Asp.net MVC. So, among other things: ViewData Model, Commands, adapting to the new views structure. In addition, I will discuss briefly automappera.


ViewData Model

What a monster of many probably will ask. These are the models (classes) used to transmit data from the controller to the view. Thanks to him views may be strongly typed to a particular model. We can thus avoid the use of ViewData and we have all the data from the view nicely in a single model. This greatly facilitates access to data. I will not elaborate too much on this subject but significantly expanded explanation can be found on this blog


BaseViewData
{public string Sitetitle {get; set;}
public string PageTitle {get; set;} public string MetaKeywords {get; set;} public string

MetaDescription {get; set;}}

 Then is a concrete example, the controller for ViewDataModel AccountViewData which is in the constructor sets the page title. Sample Implementation Account for the controller: public class 

AccountViewData: BaseViewData
{private string
_pageTitle = "Account";

public AccountViewData () {

PageTitle = _pageTitle;

}} And then

have very definite views of models that inherit from the model controller for example: public class
 
LogOnViewData: AccountViewData
{
[Required]
[DisplayName ("User name")] public string
UserName {get; set;}

[Required ]
[DataType (DataType.Password)]
[DisplayName ("Password")] public string
Password {get; set;}
 [DisplayName ("Remember me?")] public bool 
rememberMe {get; set;
}}

ViewData generation of models is done using the factory so that a particular controller does not have to know a variable with Site.Mastera. Examples of the creation of a model for the controller ViewData Account Login View Public ActionResult

Logon () {

LogOnViewData _viewDataFactory.Create \u0026lt;LogOnViewData> view = ();

return View (view);}



Commands
 Next item associated with the views of the commandy. They are used to bound with BIA data that form to send us a specific controller. This allows us to write a public 

ActionResult Register (RegisterCommnad command)

instead: public

ActionResult Register (FormCollection formitems)

and draw from this field.
Automapper
 Automapper is a small library to facilitate the mapping of object to another object. This is useful mainly in the transformation of the entity at the DTI. The same map after setting looks like this: 
testuser User testuser = new ();
UserDTO testUserDTO = Mapper.Map \u0026lt;User, UserDTO> (testuser);
 
As you can see nice, easy and fun. Now a few words about the configuration. Let's start by creating a profile that is the class who has information on how to map the objects. It looks like this: public class

DefaultProfile: Profiles
{public override string ProfileName
{get {
 return "DefaultProfile" 

}}

protected override void Configure () {
 
/ / configure here
types / / Example of the User UserDTO
Mapper.CreateMap \u0026lt;User, UserDTO & # 62; ()
. ForMember (dest => dest.Id, opt => opt.MapFrom (src => src.Id))
/ / gave only the first field analogy, but the rest

}}

Then we create a Bootstrapper task that will be it for us at the beginning of configurations wczytywał: public class

AutoMapperConfiguratorTask : BootstrapperTask
{protected override
TaskContinuation ExecuteCore (IServiceLocator serviceLocator)
{
Mapper.Initialize (x => x.AddProfile \u0026lt;DefaultProfile> ());

TaskContinuation.Continue return;}

}

 I already have configured automappera. This is a very useful library for easy lives. In addition to these major changes as described in the alert. I added a simple service associated with the user and accordingly modified the controllers and views. So I have a simple login working. 


Sunday, August 8, 2010

Maybelline Dream Blush Peach Satin Swatch

Asp.net MVC - IoC and Bootstrapper. Introduction to Library

Then the interface database I decided to get on the Bootstrapper and implement IoC container. Tell a little bit here about the MVC pattern of DI and by way of introduction


dependancy injection and Inversion of Control (IoC)

dependancy injection (injecting dependencies) design pattern is that of eliminating the direct dependence between the components for a plugin architecture. In practice, it looks like the interface is used instead of concrete classes which makes them can easily be around with. Through this technique, we can create easily testable objects.

Asp.net MVC
Model: It is a component that consists of business objects (entities) as well as business logic. Generally, this part is responsible for drawing and storing data in a database.
View: Views are components that display the user interface. After appropriate processing the object code is the html code (for web applications) and other associated technologies. Typically, views are generated in the leaning data model.
Controller: Controllers are designed to handle interactions with, work with the data model view and choose which display in May.

For more information, see the page I recommend Asp.net MVC. After a brief introduction, we can return to the main topic.


Bootstrapper

What is this Bootstraper probably ask. It is an object that is executed at the beginning of the web application. Aims to create basic configurations and perform tasks that are necessary before the application can be run IoC container such as registration, routing configuration, adding his own factory inspectors. Well, I mentioned in the title collection of MVC Extensions much to facilitate this action because the majority is already in less concluded. Let's start from the beginning. The first step is to replace the HttpApplication object from the Global.asax with the appropriate library MVC Extensions. In my case, it will be because I use UnityMvcApplication Unity container. Global.asax will now look like this: public class

MvcApplication: UnityMvcApplication
} {

As you can see nothing special. But what makes me like we will not have to manually create UnityControllerFactory which is necessary for our application is running with this container. Also, this class will perform basic tasks associated with Asp.net MVC as well as their own which we can implement. In addition, we add an object that implements the interface IModule. It will be used to configure the IoC container. Public class
RegisterServices: IModule
{public void Load (IUnityContainer container)
 {/ / here you configure the container. Add the repositories, services. 

}}


Bootstrapper Tasks
 
first task that is associated directly with Asp.net MVC is a class which we will set up your routing. It must inherit from class RegisterRoutesBase. Sample implementation: public class

RegisterRoutes: RegisterRoutesBase

{protected override void Register (RouteCollection routes)

{/ / here we routing configuration in August.

}} Another interesting task but not required is a class that allows us to filter the global configuration. In short, allow us to inject dependencies to filter because normally there is no way to do it. About specific solutions and examples I'll write later. Sample implementation: public class

RegisterGlobalFilters: ConfigureFiltersBase
 
{protected override void Configure (IFilterRegistry registry)

{/ / here we register the global filters
registry.Register \u0026lt;HomeController, MyCustomAttribute> ();}

}
In addition to these specific tasks that must be performed before an application can define your own. These objects must inherit from BootstrapperTask. For me that would like to initiate IoC container class that provides the application: public class
 RegisterIoC: BootstrapperTask 
{protected override
TaskContinuation ExecuteCore (IServiceLocator serviceLocator)
{
IoC.InitializeWith (serviceLocator);

TaskContinuation.Continue return;}

}

incomprehensible element can only be here for the return type TaskContinuation. It can take three values: Continue, Skip, and Break. Continue will perform the following tasks in order of normal, Skip causes bypass of the one of the tasks of the Break will cease to hold the next task.
 
As you can see a collection of MVC Extensions life easier for us because it has many interesting solutions. I highly recommend you read this. In addition, many solutions of these libraries will be seen in Asp.net 3.0 MVC