Posts

Showing posts from September, 2019

How Dependency Injection Containers Work in C#?

Dependency Injection (DI) containers, such as Unity or DryIoc, help manage the creation and lifetime of object dependencies in C#. They facilitate the Inversion of Control (IoC) principle, allowing you to focus on writing clean, maintainable code without worrying about the complexities of instantiating dependencies manually. How DI Containers Work? Registration:  You define which concrete classes should be used to fulfill specific interface contracts. This allows the DI container to know what to instantiate when a class requests a particular dependency. Resolution:  When an instance of a class is requested, the DI container looks at the registered services, resolves the dependencies, and creates the object with the required dependencies injected. Lifetime Management:  The container manages the lifecycle of the dependencies. You can specify whether instances should be singleton (one instance for the entire application), transient (a new instance each time), or scoped (one ...

Filter DataGrid and ListView in wpf using ICollectionView

Image
EmployeeDetails.xaml <UserControl x:Class="PrismMain.Views.EmployeeDetails"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         xmlns:local="clr-namespace:PrismMain.Views"         mc:Ignorable="d"        >     <Grid HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,50,0,0">         <Grid.RowDefinitions>             <RowDefinition Height="50"/>             <RowDefinition Height="*"/>             <RowDefinition Height="*"/> ...

How to use Prism Region in WPF?

Image
Step 1: Install Prism.Core,Prism.DryIoc (You can use any IOC like Prism.Unity),Prism.Wpf. Step 2: Add the prism namespace to  MainWindow.xaml   like below                            xmlns:prism="http://prismlibrary.com/" Step 3: Add ContentControl  to  MainWindow   and initilize the RegionName <Grid>         <ContentControl prism:RegionManager.RegionName =" MainRegion "/>     </Grid> Step 4: Implement IModule  class MainModule : IModule     {         public void OnInitialized (IContainerProvider containerProvider)         {            var region= containerProvider.Resolve<IRegionManager>();             region.RegisterViewWithRegion(" MainRegion ", typeof( TabView ));       ...

Is it possible not to implement interface method in implementation class?

Yes, it is indeed possible to avoid implementing interface methods in the implementation class. To achieve this, you can declare the methods you don't wish to implement as abstract within the interface. By doing so, you'll need to mark the class as abstract as well. This allows you to provide the implementation of the method in a derived class of the abstract class. Let's take an example scenario using C#: interface ITest  {         void Sum();  } abstract class SumTest : ITest  {        public abstract void Sum();  } In this code, the SumTest don't have the implementation of the Sum() method. This approach can be useful when you require a method implementation but don't want to provide it immediately. By using the abstract modifier, you're indicating that derived classes should implement this method. This flexibility is particularly helpful when you want to delay the implementation until a more appropriate time. ...

What is Abstraction in C#?

The process of defining a class by providing the necessary and essential details of an object to the outside world and hiding the unnecessary things is called abstraction in C#. In C# we can hide the member of a class by using private access modifiers. Let us understand this with a car example. As we know a car is made of many things, such as the name of the car, the color of the car, gear, breaks, steering, silencer, diesel engine, the battery of the car, engine of the car, etc. Now you want to ride a car. So to ride a car you should know function of Gear,Break and Steering you no need to know engine of the car.so here in case of abstraction we can hide engine details so to do that make engine function private inside class and all require thing what we should know make it's function public.