Click here to Skip to main content
15,897,968 members
Articles / DevOps / Unit Testing

Dependency Injection and Unit Of Work using Castle Windsor and NHibernate

Rate me:
Please Sign up or sign in to vote.
4.94/5 (75 votes)
8 May 2014CPOL11 min read 270.3K   5.2K   139  
An implementation of dependency injection, repository and unit of work patterns using Castle Windsor and NHibernate.
@{
    ViewBag.Title = "Index";
}

@section styles
{
    <link rel="stylesheet" type="text/css" href="~/Scripts/jtable/themes/metro/blue/jtable.css" />
}

@section scripts
{
    <script type="text/javascript" src="~/Scripts/jtable/jquery.jtable.js"></script>

    <script type="text/javascript">
        $(function () {

            $('#PeopleTable').jtable({
                title: 'My Phone Book',
                actions: {
                    listAction: '@Url.Action("PeopleList")',
                    createAction: '@Url.Action("CreatePerson")',
                    updateAction: '@Url.Action("UpdatePerson")',
                    deleteAction: '@Url.Action("DeletePerson")'
                },
                fields: {
                    Id: {
                        key: true,
                        list: false
                    },
                    //CHILD TABLE (PHONE NUMBERS)
                    Phones: {
                        title: '',
                        width: '1%',
                        sorting: false,
                        edit: false,
                        create: false,
                        display: function (personData) {
                            //Create an image that will be used to open child table
                            var $img = $('<img class="open-child-table" src="@Url.Content("~/Content/Images/phone.png")" title="Show phone numbers" />');
                            //Open child table when user clicks the image
                            $img.click(function () {
                                $('#PeopleTable').jtable('openChildTable',
                                        $img.closest('tr'),
                                        {
                                            title: ' &gt; ' + personData.record.Name + ' - Phone numbers',
                                            actions: {
                                                listAction: '@Url.Action("PhoneList", "Home")?personId=' + personData.record.Id,
                                                createAction: '@Url.Action("CreatePhone", "Home")',
                                                updateAction: '@Url.Action("UpdatePhone", "Home")',
                                                deleteAction: '@Url.Action("DeletePhone", "Home")'
                                            },
                                            fields: {
                                                Id: {
                                                    key: true,
                                                    list: false
                                                },
                                                PersonId: {
                                                    type: 'hidden',
                                                    defaultValue: personData.record.Id
                                                },
                                                Type: {
                                                    title: 'Phone type',
                                                    width: '35%',
                                                    options: { '1': 'Home phone', '2': 'Office phone', '3': 'Cell phone' }
                                                },
                                                Number: {
                                                    title: 'Phone Number',
                                                    width: '35%'
                                                },
                                                RecordDate: {
                                                    title: 'Record date',
                                                    width: '30%',
                                                    type: 'date',
                                                    displayFormat: 'dd.mm.yy',
                                                    create: false,
                                                    edit: false
                                                }
                                            }
                                        }, function (data) { //opened handler
                                            data.childTable.jtable('load');
                                        });
                            });
                            //Return image to show on the person row
                            return $img;
                        }
                    },
                    Name: {
                        title: 'Name',
                        width: '30%'
                    },
                    CityId: {
                        title: 'City',
                        width: '30%',
                        options: '@Url.Action("CityList")'
                    },
                    BirthDay: {
                        title: 'Birth day',
                        width: '20%',
                        type: 'date',
                        displayFormat: 'dd.mm.yy'
                    },
                    Notes: {
                        title: 'Additional notes',
                        type: 'textarea',
                        list: false
                    },
                    RecordDate: {
                        title: 'Record date',
                        width: '20%',
                        type: 'date',
                        displayFormat: 'dd.mm.yy',
                        create: false,
                        edit: false
                    }
                }
            });

            $('#PeopleTable').jtable('load');

        });
    </script>
}

<div id="PeopleTable"></div>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Volosoft
Turkey Turkey
I have started programming at 14 years old using Pascal as hobby. Then I interested in web development (HTML, JavaScript, ASP...) before university.

I graduated from Sakarya University Computer Engineering. At university, I learned C++, Visual Basic.NET, C#, ASP.NET and Java. I partly implemented ARP, IP and TCP protocols in Java as my final term project.

Now, I am working on Windows and web based software development mostly using Microsoft technologies in my own company.

My open source projects:

* ABP Framework: https://abp.io
* jTable: http://jtable.org
* Others: https://github.com/hikalkan

My personal web site:

https://halilibrahimkalkan.com

Comments and Discussions