<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.NET Tutorials | Student Projects</title>
	<atom:link href="https://studentprojects.in/category/software-development/dotnet/dotnet-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Sat, 10 Dec 2022 03:55:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Dependency Injection in C# .NET</title>
		<link>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/dependency-injection/</link>
					<comments>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/dependency-injection/#comments</comments>
		
		<dc:creator><![CDATA[Ranjan]]></dc:creator>
		<pubDate>Fri, 20 Jan 2012 01:56:01 +0000</pubDate>
				<category><![CDATA[.NET Tutorials]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=2578</guid>

					<description><![CDATA[<p>Dependency injection basically allows us to create loosely coupled, reusable, and testable objects in your software designs by removing dependencies. We will take a look into the Object dependencies before digging in more. Consider a scenario of fetching an employee details and show display in UI. Let us say create a Business logic layer class</p>
<p>The post <a href="https://studentprojects.in/software-development/dotnet/dotnet-tutorials/dependency-injection/">Dependency Injection in C# .NET</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Dependency injection basically allows us to create loosely coupled, reusable, and testable objects in your software designs by removing dependencies.</p>
<p>We will take a look into the Object dependencies before digging in more.<br />
Consider a scenario of fetching an employee details and show display in UI. Let us say create a Business logic layer class named EmployeeBAL and a data access layer class named EmployeeDAO</p>
<figure style="width: 300px" class="wp-caption alignright"><img decoding="async" title="Dependency Injection" src="https://studentprojects.in/wp-content/uploads/2012/01/dependency-injection.jpg" alt="Dependency Injection" width="300" height="200" /><figcaption class="wp-caption-text">Dependency Injection</figcaption></figure>
<p>public class EmployeeDao<br />
{<br />
//Some code<br />
}</p>
<p>public class EmployeeBAL<br />
{<br />
var employeeDAO = new EmployeeDao();<br />
//Some code<br />
}</p>
<p>From the above code you will notice one thing that we are creating EmployeeDAO instance inside the Business logic layer class. So here comes the dependency</p>
<h2><strong>What is wrong if we have a dependency?</strong></h2>
<p>Think about whether your code is unit testable. We cannot fully unit test the EmployeeBAL as it has a dependency on Employee DAO. So we can say as long as the composition of the DAO exists within the BAL we cannot unit test the EmployeeBAL.</p>
<p>You will also notice one more thing here; with this type of implementation you will see a high coupling of BAL and DAL.</p>
<h2><strong>How to make it loose coupling?</strong></h2>
<p>The basic idea behind Dependency Injection is that you should isolate the implementation of an object from the construction of objects on which it depends.</p>
<p>Coming to the example, we should be isolating the implementation of EmployeeBAL object and the construction of the dependent EmployeeDAO object.</p>
<p>We will see how we can make loosely coupled objects in detail</p>
<h2><strong> Constructor based dependency injection</strong></h2>
<p>We will have to modify the EmployeeBAL to accept an EmployeeDAO instance within its constructor.</p>
<p>public class EmployeeDao<br />
{<br />
//Some code<br />
}</p>
<p>public class EmployeeBAL<br />
{<br />
EmployeeDao employeeDAO;</p>
<p>public EmployeeBAL(EmployeeDAO employeeDao){<br />
this.employeeDAO = employeeDao;<br />
}<br />
//Some code<br />
}</p>
<h2><strong> Property based dependency injection</strong></h2>
<p>With property based injection we will have a public getter and setter Property of type EmployeeDao so that the dependency can be externally set.</p>
<p>public class EmployeeBAL<br />
{<br />
Public EmployeeDao EmployeeDataAccess{ get; set; }<br />
}</p>
<p>var employeeBAL = new EmployeeBAL();<br />
EmployeeBAL.EmployeeDataAccess = new EmployeeDao();</p>
<p>Wait!!!</p>
<p>The above ones are just some techniques of injecting the dependency. We are still yet to discuss one more interesting thing Unit Testing.</p>
<p>Are you agreeing that we have removed the DAO creation from the Business Logic EmployeeBAL? Yes it is good but it still depends on the actual instance of EmployeeDao.</p>
<p>Consider the below mentioned implementation of the same sample senarios</p>
<p>interface IDataAccess<br />
{<br />
//Some code<br />
}</p>
<p>class EmployeeDao : IDataAccess<br />
{<br />
//Some code<br />
}</p>
<p>public class EmployeeBAL<br />
{<br />
private IDataAccess dataAccess;<br />
public BusinessFacade(IDataAccess dao)<br />
{<br />
dataAccess = dao;<br />
}<br />
}</p>
<p>You can notice we are doing a constructor dependency injection but most important thing here<br />
is we are using Interface type than creating a strongly typed object.</p>
<p>The advantage that we are getting here is we can have an in memory data access object of<br />
IDataAccess interface type and we can easily inject the dependency to the EmployeeBAL.<br />
By this way we no need to have the actual database dependency.</p>
<p>Are you happy that we can unit test the BAL without the data access dependency?</p>
<h2><strong>Advantages of Dependency Injection</strong></h2>
<p>The primary advantages of dependency injection are:<br />
Loose coupling<br />
Centralized configuration<br />
Easily testable</p><p>The post <a href="https://studentprojects.in/software-development/dotnet/dotnet-tutorials/dependency-injection/">Dependency Injection in C# .NET</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/dependency-injection/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>Delegate and Events in C# .NET</title>
		<link>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/delegate-events-net/</link>
					<comments>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/delegate-events-net/#comments</comments>
		
		<dc:creator><![CDATA[Ranjan]]></dc:creator>
		<pubDate>Sun, 15 Jan 2012 16:54:06 +0000</pubDate>
				<category><![CDATA[.NET Tutorials]]></category>
		<category><![CDATA[Delegates]]></category>
		<category><![CDATA[Events]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=2560</guid>

					<description><![CDATA[<p>Delegates A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which</p>
<p>The post <a href="https://studentprojects.in/software-development/dotnet/dotnet-tutorials/delegate-events-net/">Delegate and Events in C# .NET</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><strong>Delegates</strong></p>
<p>A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.</p>
<p>The signature of a single cast delegate is shown below:</p>
<p><strong>delegate result-type identifier ([parameters]);</strong></p>
<p>where:</p>
<ul>
<li>result-type: The result type, which matches the return type of the function.</li>
<li>identifier: The delegate name.</li>
<li>parameters: The Parameters that the function takes.</li>
</ul>
<p>Delegates allow a clearer separation of specification and implementation. A delegate specifies the signature of a method, and authors can write methods that are compatible with the delegate specification.</p>
<p><strong>Multicast delegates</strong></p>
<p>With multicast delegate, it is just like a normal delegate but it can point to multiple functions so on invocation of such delegate it will invoke all the methods and functions associated with the same one after another sequentially.</p>
<p><strong>Events: </strong></p>
<p>Events are wrapper around the delegate. It sits on top of the delegate and provides only the necessary encapsulation so that the destination objects can subscribe to the Event and not have full control on the delegate object.</p>
<p>Events are declared using delegates. The delegate object encapsulates a method so that it can be called anonymously. An event is a way for a class to allow clients to give it delegates to methods that should be called when the event occurs. When the event occurs, the delegate(s) given to it by its clients are invoked.<br />
We will consider an example implementation of Logger application, which can be used to log messages in Console, File or Database etc.</p>
<figure id="attachment_2585" aria-describedby="caption-attachment-2585" style="width: 265px" class="wp-caption alignleft"><a href="https://studentprojects.in/wp-content/uploads/2012/01/ClassDiagram-e1326646129665.png"><img decoding="async" loading="lazy" class="wp-image-2585 size-medium" title="ClassDiagram of Logger Application" src="https://studentprojects.in/wp-content/uploads/2012/01/ClassDiagram-e1326646265275-265x300.png" alt="ClassDiagram of Logger Application" width="265" height="300"></a><figcaption id="caption-attachment-2585" class="wp-caption-text">Logger Application ClassDiagram</figcaption></figure>
<p>We will declare a delegate named LogWriteDelegate which accepts one parameter named message.</p>
<p><code>public delegate void LogWriteDelegate(string message);</code></p>
<p>Next we will declare an Event of type LogWriteDelegate</p>
<p><code>public event LogWriteDelegate LogWriteEvent;</code></p>
<p>In our sample Logger the FileLogger and ConsoleLogger will subscribe or register to the above mentioned event so that when the Write method of logger is called the respective logic within the Write method of FileLogger and ConsolLogger will also gets invoked.</p>
<p><code>using (var logger = new Logger("testing", EntryType.Debug))<br />
{<br />
logger.LogWriteEvent += new Logger.LogWriteDelegate(consoleLogger.Write);<br />
logger.LogWriteEvent += new Logger.LogWriteDelegate(fileLogger.Write);<br />
logger.Write();<br />
}</code></p>
<p>You can notice here a multicast delegate; the LogWriteEvent is being registered with Console and File log write methods.</p>
<p>While firing an Event within the Logger object, it is always a good practice to check whether the event is registered or not.</p>
<p><code>public void Write()<br />
{<br />
if (LogWriteEvent != null)<br />
LogWriteEvent(ToString());<br />
}</code></p>
<p>Here the LogWriteEvent holds the address of the methods console.Write and fileLogger.Write. When firing an event it will sequentially call the respective methods which are pre-registered to this Event.</p>
<p>Note: The Logger application is designed in such a way that in future you can have multiple implementations of Loggers. Right now we have Console and File Logger; if you are interested in implementing a Database logger we can create a new Class named DatabaseLogger which will implement ILogger interface. Provide necessary Write method logic so that it will log messages to database.</p>
<p>Ones you have done with the DatabaseLogger implementation, you just have to create an instance and register the event as we have done for Console and File Loggers.</p>
<p><a href="https://studentprojects.in/wp-content/uploads/2012/01/LoggerLibrary.zip">Download Sample Logger Application</a></p><p>The post <a href="https://studentprojects.in/software-development/dotnet/dotnet-tutorials/delegate-events-net/">Delegate and Events in C# .NET</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/delegate-events-net/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Introduction to Automapper</title>
		<link>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/introduction-automapper/</link>
					<comments>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/introduction-automapper/#respond</comments>
		
		<dc:creator><![CDATA[Ranjan]]></dc:creator>
		<pubDate>Mon, 02 Jan 2012 05:25:10 +0000</pubDate>
				<category><![CDATA[.NET Tutorials]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=2504</guid>

					<description><![CDATA[<p>Introduction AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type. When to use Automapper? Here is one Sample scenario. Assume we have a domain model say a Customer entity and we are planning to show a list of Customers in</p>
<p>The post <a href="https://studentprojects.in/software-development/dotnet/dotnet-tutorials/introduction-automapper/">Introduction to Automapper</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type.</p>
<p><strong>When to use Automapper?</strong></p>
<p>Here is one Sample scenario. Assume we have a domain model say a <code>Customer</code> entity and we are planning to show a list of <code>Customers</code> in a UI, for that, we need a much lighter object say <code>CustomerViewModel</code>, which has a list of <code>Customer</code> objects that can be used to bind the controls in UI layer.</p>
<p>Would you like to have something that will do mapping from <code>Customer</code> to the <code>CustomerViewModel</code> automatically?</p>
<p>Of course, you do, especially if you have another situation like mapping of heavy data objects into DTO objects which are considered to be sent though the wire.</p>
<p><strong>How do I use AutoMapper?</strong></p>
<p>First, you need both a source and destination type to work with. The destination type&#8217;s design can be influenced by the layer in which it lives, but AutoMapper works best as long as the names of the members match up to the source type&#8217;s members. If you have a source member called &#8220;FirstName&#8221;, this will automatically be mapped to a destination member with the name &#8220;FirstName&#8221;.</p>
<p>Once you have your types, and a reference to AutoMapper, you can create a map for the two types.</p>
<p><code>Mapper.CreateMap&lt;Order, OrderDto&gt;();</code></p>
<p>The type on the left is the source type, and the type on the right is the destination type. To perform a mapping, use the Map method.</p>
<p><code>OrderDto dto = Mapper.Map&lt;Order, OrderDto&gt;(order);<br />
</code><br />
AutoMapper also has non-generic versions of these methods, for those cases where you might not know the type at compile time.</p>
<p><strong>Where do I configure AutoMapper?</strong></p>
<p>If you&#8217;re using the static Mapper method, configuration only needs to happen once per AppDomain. That means the best place to put the configuration code is in application startup, such as the Global.asax file for ASP.NET applications. Typically, the configuration bootstrapper class is in its own class, and this bootstrapper class is called from the startup method.</p>
<p><strong>Samples and DLL’s: </strong></p>
<p><a href="http://www.codeproject.com/KB/library/AutoMapper.aspx">http://www.codeproject.com/KB/library/AutoMapper.aspx</a></p>
<p><a href="http://automapper.codeplex.com/">http://automapper.codeplex.com/</a></p><p>The post <a href="https://studentprojects.in/software-development/dotnet/dotnet-tutorials/introduction-automapper/">Introduction to Automapper</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/introduction-automapper/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>3-Tier Architecture in .NET</title>
		<link>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/3tire-architecture/</link>
					<comments>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/3tire-architecture/#respond</comments>
		
		<dc:creator><![CDATA[Ranjan]]></dc:creator>
		<pubDate>Sun, 01 Jan 2012 13:54:53 +0000</pubDate>
				<category><![CDATA[.NET Tutorials]]></category>
		<category><![CDATA[3-Tire]]></category>
		<category><![CDATA[N-Tire Architecture]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=2471</guid>

					<description><![CDATA[<p>3-Tier architecture generally contains User Interface (UI) or Presentation Layer, Business Access/Logic Layer (BAL) and Data Access Layer (DAL).</p>
<p>The post <a href="https://studentprojects.in/software-development/dotnet/dotnet-tutorials/3tire-architecture/">3-Tier Architecture in .NET</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<figure id="attachment_2475" aria-describedby="caption-attachment-2475" style="width: 268px" class="wp-caption alignleft"><a href="https://studentprojects.in/wp-content/uploads/2012/01/N-TireSnapshot.png"><img decoding="async" loading="lazy" class="wp-image-2475 size-medium" title="Solution Explorer" src="https://studentprojects.in/wp-content/uploads/2012/01/N-TireSnapshot-268x300.png" alt="Solution Explorer" width="268" height="300" /></a><figcaption id="caption-attachment-2475" class="wp-caption-text">Snapshot</figcaption></figure>
<p><strong>Introduction</strong></p>
<p>3-Tier architecture generally contains User Interface (UI) or Presentation Layer, Business Access/Logic Layer (BAL) and Data Access Layer (DAL).</p>
<p><strong>Presentation Layer (UI)</strong><br />
Presentation layer is responsible for displaying the views. Contains windows forms or ASP.NET pages, where data is presented to the user or input is taken from the user. We will consider a sample Windows form application which will show the Authors information and details in the UI.</p>
<p><strong>Business Access Layer (BAL) or Business Logic Layer </strong></p>
<p>BAL contains business logic, validations or calculations related with the data</p>
<p><strong>Business Entities</strong></p>
<p>Business entities are reusable entities developed as per the application. We are making use of these entities in BAL and DAL. The data access layer fetches the data and converts the data say to a List of business entity. Ex: When we are retrieving a list of Authors details, the DAL will fetch all the authors and returns List&lt;AuthorsBE&gt; list of author’s business entities.</p>
<p><strong>Data Access Layer (DAL)</strong></p>
<p>DAL contains methods that helps business layer to connect the data and perform required action, might be returning data or manipulating data (insert, update, delete etc). For this demo pubs sample application, the BAL makes a call to data access to get all the list of authors i.e GetAllAuthors(), to get all the list of author titles GetAuthorTitleDetails(string authorID)</p>
<p>&nbsp;</p>
<p><strong>Advantages of N-Tier Application</strong></p>
<ol>
<li>Decoupling the logic: By loose coupling the logics of Presentation, Business and Data access suppose if there is a change in the UI layer, you will only have to only about the modifications in the Presentation layer. Right now it is using SQL Server database so in future is there is a change in the database we will have to modify the logic with in the Data access layer and nothing else.</li>
<li>With layered architecture you can do the software development in Parallel. That means you can code each layers independently</li>
<li>Easy to Test: The testability of the software increases by decoupling the logics into multiple layers. You can independently Unit Test the logics of different layers</li>
<li>Reusability of Components</li>
</ol>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>How to run the sample:</strong></p>
<ol>
<li>Download pubs database sample from <a href="http://www.microsoft.com/download/en/details.aspx?id=23654">http://www.microsoft.com/download/en/details.aspx?id=23654</a> link</li>
<li>Install the MSI: SQL2000SampleDb.msi , run the scripts to create Pubs database.</li>
<li>Download the sample project for this article from the below mentioned link for &#8216;Sample Project for Download&#8217;</li>
<li>Open SQL Management studio and execute the stored procedures with in the DataAccessLayer &#8211; &gt; Scripts folder in Pubs database.</li>
<li>Open PubsSamplePresentation.sln Solution from VS 2010 or VS2011</li>
<li>Go to PubsSamplePresentation and open App.config</li>
<li>Change the connection string (PubsConnectionString) value appropriately</li>
<li>Run the Windows Form application &#8211; PubsSamplePresentation</li>
</ol>
<p>Sample Project for Download: <a href="https://studentprojects.in/wp-content/uploads/2012/01/PubsSamplePresentation.zip">PubsSamplePresentation</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p><p>The post <a href="https://studentprojects.in/software-development/dotnet/dotnet-tutorials/3tire-architecture/">3-Tier Architecture in .NET</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/dotnet/dotnet-tutorials/3tire-architecture/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
