Monday, May 12, 2014

Prism Interview Questions and Answers

Prism Interview Questions and Answers


What is Prism? 


Prism is the framework or the set of guidelines which is used to develop the WPF desktop application as well as the Silverlight Rich Internet applications(RIA). So it’s a kind of Design pattern to Develop the XMAL based application. It also used to develop the Windows 7 applications. Prism mainly helps to design the loosely coupled components which can be easily integrated with the other components of the overall application. Prism mainly used to build the composite applications which need various other components to be integrated.


Prism has RegionManager, EventAggregator and Commands all with the purpose of solving decoupling issues related to UI components.


Prism mainly guides of creating the applications using the Model-View-ViewModel (MVVM) model, Managed Extensibility Framework (MEF), and navigation in the application.


To use the Prism framework, we need to use their library called as Prism Library. So prism Library is the in-built set of components which can be used in developing the WPF and Silverlight applications.


What are objectives of Prism?


Following are the objectives of using Prism.


  • Create an application from modules that can be built, assembled, and, optionally, deployed by independent teams using WPF or Silverlight.

  • Minimize cross-team dependencies and allow teams to specialize in different areas, such as user interface (UI) design, business logic implementation, and infrastructure code development.

  • Use an architecture that promotes reusability across independent teams.

  • Increase the quality of applications by abstracting common services that are available to all the teams.

  • Incrementally integrate new capabilities.

What is Dependency Injection?


Dependency Injection is a practice where objects are designed in a manner where they receive instances of the objects from other pieces of code, instead of constructing them internally. This means that any object implementing the interface which is required by the object can be substituted in without changing the code, which simplifies testing, and improves decoupling.


Let’s assume that we have object dependency when an object ‘x’ uses an object ‘y’, we say that ‘x’ is dependent on ‘y’. Object dependency becomes a problem when object ‘x’ needs to use another object dynamically, object ‘z’, instead of ‘y’. Strong dependency mixes both object (Data) and relation (logic) in one place and result in tight coupling that render the code much harder to modify and adjust. Dependency injection allows objects to relate to each other but through an interface so that object ‘x’ will use interface ‘i’ while both ‘y’ & ‘z’ implement the interface ‘i’. This methodology allows the isolation between the implementation, creation, and logical dependency of an object.


The Prism Library includes the UnityBootstrapper and MefBootstrapper classes, which implement most of the functionality necessary to use either Unity or MEF as the dependency injection container in your application. In addition to the stages shown in the previous illustration, each bootstrapper adds some steps specific to its container.


What is an Event Aggregator?


EventAggregator is the utility service which contains the events and allows the decouple the publisher and subscriber so that they can be buildup independently. Decouple is primarily useful when a new module needs to be added or removed or modified. The new module can be added as per the event fired and defined in the shell.


The EventAggregator service is primarily a container for events that allow decoupling of publishers and subscribers so they can evolve independently. This decoupling is useful in modularized applications because new modules can be added that respond to events defined by the shell or, more likely, other modules.


In the Composite Application Library, EventAggregator allows subscribers or publishers to locate a specific EventBase. The event aggregator also allows for multiple publishers and multiple subscribers, as shown in figure below.

The EventAggregator class is offered as a service in the container and can be retrieved through the IEventAggregator interface. The event aggregator is responsible for locating or building events and for keeping a collection of the events in the system.


The real work of connecting publishers and subscribers is done by the CompositePresentationEvent class. This is the only implementation of the EventBase class that is included in the Composite Application Library. This class maintains the list of subscribers and handles event dispatching to the subscribers.


What is Shell?


The shell is the main window of the application where the primary user interface (UI) content is contained. The shell may be composed of multiple windows if desired, but most commonly it is just a single main window that contains multiple views. The shell may contain named regions where modules can specify the views that will appear. It may also define certain top-level UI elements, such as the main menu and toolbar. The shell defines the overall appearance for the application. It may define styles and borders that are present and visible in the shell layout itself, and it may also define styles, templates, and themes that get applied to the views that are plugged into the shell. 


What is view? 


Views are the composite portions of the user interface that are contained in the shell’s window(s). It is easiest to think about a view as a user control that defines a rectangular portion of the client area in the main window. However, views in the Composite Application Library do not have to be defined with a user control. You can use a Windows Presentation Foundation (WPF) data template to define a view that will be rendered based on the data in your model. A view could also share screen real estate with other views due to the rendering and compositing capabilities of WPF. In simple terms, a view is just a collection of user interface elements that define part of the rendering of the user interface. It is a unit of encapsulation for defining the separable portions of your UI.


What is Bootstrapper?


Bootstrapper is an utility in WPF engine which is mainly responsible for the initialization of the application by using the composite application library. By using the bootstrapper we can find out how the components of the application are wired up in the composite application library. The bootstrapper responsibility to create the Shell or main window. Composite application library has the default abstract class UnityBootstrapper which actually handles the initialization.


A bootstrapper is a class that is responsible for the initialization of an application built using the Prism Library. By using a bootstrapper, you have more control of how the Prism Library components are wired up to your application.


The Prism Library includes a default abstract Bootstrapper base class that can be specialized for use with any container. Many of the methods on the bootstrapper classes are virtual methods. You can override these methods as appropriate in your own custom bootstrapper implementation.


What are the basic stages of bootstrapping process? 


Basic stages of the bootstrapping process are as follows.


The Prism Library provides some additional base classes, derived from Bootstrapper, that have default implementations that are appropriate for most applications. The only stages left for your application bootstrapper to implement are creating and initializing the shell.


What is ILoggerFacade? 


ILoggerFacade is an interface used in Prism Framework for logging purpose.


The simplest approach to logging in Prism is to override the LoggerFacade property in your Bootstrapper. By overridding the LoggerFacade, you can pass in an instance of any Logger you want with any configuration needed as long as the logger implements the ILoggerFacade interface.


A simple Example is given below. 


using log4net;


using Microsoft.Practices.Prism.Logging;


namespace FsNoteMaster3



class Log4NetLogger : ILoggerFacade



#region Fields


 


// Member variables


private readonly ILog m_Logger = LogManager.GetLogger(typeof(Log4NetLogger));


 


#endregion


 


#region ILoggerFacade Members


 


/// <summary>


/// Writes a log message.


/// </summary>


/// <param name=”message”>The message to write.</param>


/// <param name=”category”>The message category.</param>


/// <param name=”priority”>Not used by Log4Net; pass Priority.None.</param>


public void Log(string message, Category category, Priority priority)



switch (category)



case Category.Debug:


m_Logger.Debug(message);


break;


case Category.Warn:


m_Logger.Warn(message);


break;


case Category.Exception:


m_Logger.Error(message);


break;


case Category.Info:


m_Logger.Info(message);


break;




 


#endregion




 What are Region and Region Managers?


In Prism framework, we define the region through XAML code and once a region is defined, automatically it will be registered with the RegionManager. Actually the Bootstrapper registers a service called the RegionManager at run time.


RegionManager is a dictionary where the key is name of the region. The value of the key is the reference of the IRegion interface. RegionAdapter is used to create the instance reference of the IRegion interface.


What are MEF and Unity?


Unity is mostly used for static dependencies and is more an “internal” technology, meaning outsiders do not need to know that unity is being used in the application. Unity is a IOC container. Use it to make your app more loosely coupled.


The MEF (Managed Extensibility Framework) is the new concept in .net 4.0. It is used to create the lightweight and extensible applications to create Managed Extensibility Framework. It is not only allows the extension but also reused within the application.


MEF should be used for dynamic dependencies, it is great at dynamically loading components and with the use of attributes it make creating application extensions or an application that can be extended by others easy and streamlined.


How to navigate to another page in WPF?


There is a class NavigationService which can be used for navigation of the WPF window:


this.NavigationService.GoForward();


OR



this.NavigationService.Navigate(“NextPage.xaml”)




Prism Interview Questions and Answers

No comments:

Post a Comment